win10类型按钮

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:Transfer4UI.ItemControl">
    <ControlTemplate x:Key="MinizeButonTemplate" TargetType="{x:Type local:EmbededButton}">
        <Border BorderThickness="1" Background="{TemplateBinding Background}" >
            <Grid x:Name="embedButtonGrid" ToolTip="{TemplateBinding ToolTip}" >
                <Rectangle Fill="White" Width="10" Height="3" SnapsToDevicePixels="True"></Rectangle>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="true">
                <Setter TargetName="embedButtonGrid" Property="Background" Value="Black"/>
            </Trigger>
            <Trigger Property="IsPressed" Value="true">
                <Setter TargetName="embedButtonGrid" Property="Background" Value="white"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="ResizeWindowRadioButtonTemplate" TargetType="{x:Type local:EmbedCheckBox}">
        <Border Background="{TemplateBinding Background}" >
            <Grid x:Name="ResizeWinGrid" ToolTip="{TemplateBinding ToolTip}">
                <Canvas ClipToBounds="True">
                    <Border Canvas.Left="4" Canvas.Top="1" BorderBrush="White" BorderThickness="1" Width="8" Height="6" Background="{TemplateBinding Background}" SnapsToDevicePixels="True"/>

                    <Border Canvas.Left="0" Canvas.Top="4" BorderBrush="White" BorderThickness="1" Width="8" Height="6" Background="{TemplateBinding Background}" SnapsToDevicePixels="True" />
                </Canvas>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="true">
                <Setter TargetName="ResizeWinGrid" Property="Background" Value="Black"/>
            </Trigger>
            <Trigger Property="IsChecked" Value="true">
                <Setter TargetName="ResizeWinGrid" Property="Background" Value="white"/>
            </Trigger>
            <Trigger Property="IsChecked" Value="false">
                <Setter TargetName="ResizeWinGrid" Property="Background" Value="{Binding Path=Background, ElementName=ResizeWinGrid}"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style TargetType="{x:Type local:EmbededButton}" BasedOn="{x:Null}">
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="Template" Value="{StaticResource MinizeButonTemplate}" />
    </Style>

    <Style TargetType="{x:Type local:EmbedCheckBox}" BasedOn="{x:Null}">
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="Template" Value="{StaticResource ResizeWindowRadioButtonTemplate}" />
    </Style>


    <Style x:Key="ControlMinButton" TargetType="{x:Type local:EmbededButton}" BasedOn="{StaticResource {x:Type local:EmbededButton}}"/>

    <Style x:Key="WinResizeButton" TargetType="{x:Type local:EmbedCheckBox}" BasedOn="{StaticResource {x:Type local:EmbedCheckBox}}"/>

</ResourceDictionary>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace Transfer4UI.ItemControl
{
    public class EmbededButton:Button
    {
        static EmbededButton()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(EmbededButton), new FrameworkPropertyMetadata(typeof(EmbededButton)));
        }
    }

    public class EmbededRadioButton:RadioButton
    {
        static EmbededRadioButton()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(EmbededRadioButton), new FrameworkPropertyMetadata(typeof(EmbededRadioButton)));
        }
    }

    public class EmbedCheckBox:CheckBox
    {
        static EmbedCheckBox()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(EmbedCheckBox), new FrameworkPropertyMetadata(typeof(EmbedCheckBox)));
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Win32 API提供了几种绘制按钮的方法,其中常用的是使用DrawFrameControl和DrawEdge函数。 以下是一个简单的示例代码,演示如何使用Win32 API在窗口中绘制按钮: ```c++ #include <windows.h> LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // 创建窗口 HWND hwnd; WNDCLASSEX wc = { sizeof(WNDCLASSEX) }; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.lpszClassName = L"ButtonDemo"; RegisterClassEx(&wc); hwnd = CreateWindowEx(0, L"ButtonDemo", L"Button Demo", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); // 消息循环 MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); // 绘制按钮外框 RECT rect = { 50, 50, 150, 100 }; DrawFrameControl(hdc, &rect, DFC_BUTTON, DFCS_BUTTONPUSH); // 绘制按钮文本 HFONT hFont = CreateFont(20, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Segoe UI"); HGDIOBJ hOldFont = SelectObject(hdc, hFont); SetBkMode(hdc, TRANSPARENT); SetTextColor(hdc, RGB(0, 0, 0)); rect.left += 10; rect.top += 10; DrawText(hdc, L"Button", -1, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); SelectObject(hdc, hOldFont); DeleteObject(hFont); EndPaint(hwnd, &ps); break; } case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; } ``` 该示例代码在窗口中绘制一个矩形按钮,并在其中添加文本。您可以使用相同的方法绘制其他类型按钮,例如圆形按钮或图像按钮

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值