开发者

Border for Dynamically created buttons in Windows Application C#.net

Hai all, I am dynamically creating button at runtime in a c#.net Windows Application, I want to draw a border for the dynamically created button how can i do it, i tried this

 private void DrawBorder(Button bt)
        {
            Graphics g = bt.CreateGraphics();
            ControlPaint.DrawBorder(g, bt.DisplayRectangle, Color.FromArgb(229, 227, 227), ButtonBorderStyle.Solid);
            g.Dispose();
        }

but it is not showing any error but i can't see any border

Please Hel开发者_StackOverflowp


If you want a button that draws differently, you should probably create a new class inheriting from Button, and in it you would override OnPaint and/or OnPaintBackground and implement your drawing logics, such as drawing a border.

The reason your current solution is not working probably depends on when you are calling your DrawBorder method. If your drawing code is not executed as part of handling an OnPaint event, then the graphics you draw will be drawn-over in the next paint.

But anyway, instead of drawing the border yourself, can't you set the Border proerpty on the Button object?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜