更改按钮表单 [英] change button form

查看:111
本文介绍了更改按钮表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在Windows窗体C#上更改按钮窗体。

谢谢....

how i can change the button form on windows form C#.
thank you....

推荐答案

为什么没有一个方法可以采用任何控制,以及将其Region设置为任意个边数的多边形...没有Paint事件或Win API?
Why not have one method that will take any Control, and set its Region to a polygon of any number of sides ... without the Paint Event, or Win API ?
private void makePolyPath(Control theControl, int nSides)
{
    // user insanity protection
    if(nSides < 3) throw new ArgumentOutOfRangeException("What is it about 'Polygon that you don't understand ?");

    var thePath = new GraphicsPath();

    var thePoints = new List<Point>();

    // assumption is made here that the Control's bounding
    // rectangle is square to keep this example simple
    int bound = theControl.Width;
    double rad = bound / 2.0;
    double angle = 2 * Math.PI / nSides;

    for (int i = 0; i < nSides; i++)
    {
        thePoints.Add
        (
            new Point
            (
                (int)(rad + (rad * Math.Sin(i * angle))),
                (int)(rad + (rad * Math.Cos(i * angle)))
            )
        );
    }

    thePath.AddPolygon(thePoints.ToArray());

    theControl.Region = new Region(thePath);
}

如果你想要一个圆形的控制,它更简单:

If you want a circular shaped Control, it's much simpler:

private void makeCirclePath(Control theControl)
{
    var thePath = new GraphicsPath();

    thePath.AddEllipse(theControl.ClientRectangle);

    theControl.Region = new Region(thePath);
}

警告:取决于您是否将控件(或表格)BackGroundimage设置为某些复杂图形,以及您的控制/表单在z顺序中与其他控件的关系,以及是否让用户在运行时移动非矩形控件:你可能会看到一些闪烁。



为了减少闪烁,我建议创建一个UserControl,设置它的'DoubleBuffered属性为true,将您想要的Control放在UserControl中,并设置UserControl的形状。当然,这意味着你需要做一些工作来揭露UserControl中的内容以供其包含的上下文使用。

Caution: depending on factors like whether you have the set a Control (or Form's) BackGroundimage to some complex graphic, and your Control/Form's relationship in the z-order to other Controls, and whether you let the user move non-rectangular Controls about at run-time: you may see some flickering.

To reduce flickering, I suggest creating a UserControl, setting its 'DoubleBuffered Property to true, putting the Control you want in the UserControl, and setting the shape of the UserControl. Of course, that means some work on your part to expose whatever in the UserControl for use by its containing contexts.


Google总是有帮助...

< a href =http://msdn.microsoft.com/en-us/library/aa289517(v=vs.71).aspx> http://msdn.microsoft.com/en-us/library/aa289517( v = vs.71).aspx [ ^ ]

回合C#中的按钮 [ ^ ]

RoundButton Windows Control - 不断减少的圈子 [ ^ ]

http://msdn.microsoft.com/en-us/library/6k15y9et(v=vs.110).aspx [ ^ ]
Google is always helps...
http://msdn.microsoft.com/en-us/library/aa289517(v=vs.71).aspx[^]
Round Button in C#[^]
RoundButton Windows Control - Ever Decreasing Circles[^]
http://msdn.microsoft.com/en-us/library/6k15y9et(v=vs.110).aspx[^]


试试这个,

Try this,
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        [DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
        private static extern IntPtr CreateRoundRectRgn
        (
            int nLeftRect, // x-coordinate of upper-left corner
            int nTopRect, // y-coordinate of upper-left corner
            int nRightRect, // x-coordinate of lower-right corner
            int nBottomRect, // y-coordinate of lower-right corner
            int nWidthEllipse, // height of ellipse
            int nHeightEllipse // width of ellipse
        );

        public Form1()
        {
            InitializeComponent();
            this.FormBorderStyle = FormBorderStyle.None;
            Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20));
        }
    }
}



或者你可以找到答案这里 [ ^ ]。



-KR


Or you may find your answer here[^] as well.

-KR


这篇关于更改按钮表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆