在Groupbox内的文本框周围绘制矩形 [英] Draw rectangle around Textbox inside a Groupbox

查看:158
本文介绍了在Groupbox内的文本框周围绘制矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为 GroupBox 中的 TextBox 控件添加自定义边框。
由于我是新来的Graphic这个东西,我很难找出问题所在。

I want to add a custom border around a TextBox control which is in a GroupBox. Since I'm new to this Graphic stuff I'm having a hard time figuring out the problem.

这是我使用的代码: / p>

This is the code i'm using:

Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint

    Dim _g As Graphics = Me.GroupBox1.CreateGraphics
    Dim pen As New Pen(Color.Red, 2.0)
    _g.DrawRectangle(pen, New Rectangle(TextBox1.Location, TextBox1.Size))
    pen.Dispose()

End Sub

这种形式是一种次要形式,显示当我点击主窗体上的按钮时。当表单加载然后消失时,红色边框出现一秒。

This form is a secondary form that shows when I click on a button from the Main form. The Red Border appears for a second when the form loads and then disappears.

推荐答案

您需要处理GroupBox绘制事件,而不是表格。

You need to handle the GroupBox paint event, not the form.

Private Sub HandleGroupBox1Paint(sender As Object, e As PaintEventArgs) Handles GroupBox1.Paint
    Using p As New Pen(Color.Red, 2.0)
        e.Graphics.DrawRectangle(p, Me.TextBox1.bound)
    End Using
End Sub

这篇关于在Groupbox内的文本框周围绘制矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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