1

早安社区

我想在表单的中心准确地绘制一个矩形。另外,我想在这个矩形下画一些文字。

对于我认为没有问题的文本,我使用以下代码:

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)

在此处输入图像描述

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

4

1 回答 1

3

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

e.Graphics.FillRectangle(Brushes.Beige, CInt(Local_Form.ClientRectangle.Width / 2) - 100, CInt(Local_Form.ClientRectangle.Height / 2) - 50, 200, 100)
于 2012-09-28T15:44:12.367 回答