获取文本框的位置

时间:2013-01-29 07:44:41

标签: c#-4.0 textbox

如何在矩形中获取文本框(x,y)的位置?

    RectangleF srcRect = new Rectangle(0, 0, this.BackgroundImage.Width,
                BackgroundImage.Height);

    int nWidth = printDocument1.PrinterSettings.DefaultPageSettings.PaperSize.Width;
    int nHeight = printDocument1.PrinterSettings.DefaultPageSettings.PaperSize.Height;
    RectangleF destRect = new Rectangle(0, 0, nWidth, nHeight);

    g.DrawImage(this.BackgroundImage, destRect, srcRect, GraphicsUnit.Pixel);

     e.Graphics.DrawString(textBox15.Text, textBox15.Font, 
                           new SolidBrush(textBox15.ForeColor), 
                          /*x location base on rectangle*/, 
                          /*y location based on rectagle8*/);

1 个答案:

答案 0 :(得分:0)

以下是提示使用.Right.Top

e.Graphics.DrawString(textBox15.Text, textBox15.Font, new SolidBrush(textBox15.ForeColor), srcRect.Right, srcRect.Top);