VB.net 在窗体中央绘制矩形 [英] VB.net Drawing rectangle in the center of the form

查看:41
本文介绍了VB.net 在窗体中央绘制矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好社区

我想在表单的正中央绘制一个矩形.另外,我想在这个矩形下画一些文字.

I want to draw a rectangle exactly in the center of the form. Also, I want draw under this rectangle some text.

加上文字我认为没有问题,我使用如下代码:

With the text I think that I don't have a problem, I use the following code:

Dim sf As New StringFormat
        sf.LineAlignment = StringAlignment.Center
        sf.Alignment = StringAlignment.Center

        ' Line with the problem
        e.Graphics.FillRectangle(Brushes.Beige, CInt(Local_Form.Width / 2), CInt(Local_Form.Height / 2), 200, 100)

        e.Graphics.DrawString(Local_Text, _
                              New Font(MyCloud.Settings.Settings_Forms.Font.Name, 30), _
                              Brushes.GreenYellow, _
                              Local_Form.Width / 2, Local_Form.Height / 2, sf)

但是,我对矩形有问题.有人可以帮助我吗?

But, I have problems with the rectangle. Somebody can help me?

推荐答案

两件事,第一是你将矩形的左上角设置为中心,你需要减去一半的宽度和一半的您从顶部和左侧位置的高度.此外,您应该使用 ClientRectangle 以获得没有 Chrome 的实际工作表面.

Two things, the first is that you are setting your upper left corner of your rectangle to the center, you need to subtract half of your width and and half of your height from your Top and Left position. Also you should be using the ClientRectangle to get the actual working surface without the Chrome.

e.Graphics.FillRectangle(Brushes.Beige, CInt(Local_Form.ClientRectangle.Width / 2) - 100, CInt(Local_Form.ClientRectangle.Height / 2) - 50, 200, 100)

这篇关于VB.net 在窗体中央绘制矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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