请问各位,在使用DrawString在picturebox上画画时,如何让在靠右边缘上的整行文字进行右对齐?
希望能得到函数,谢谢~~~
希望能得到函数,谢谢~~~
解决方案 »
- 关于 webbrowse 的不执行问题
- 怎么实现这个功能?
- listview为什么只能选中一整行或者某行中的第一列?
- 急!!!!!!!!!!!!!在线等,winfrom的msbuilder的调用问题,以及c#代码实现将一个文件夹作为资源文件夹加入到另一个winform中
- 请问:用<location>来允许用户不登录访问某些页面时,能否批量设置?
- 数组使用(或生命周期)的问题
- 请教,怎么获得、设置某个应用程序的位置?
- HttpWebRequest 的问题
- C# 中调用 managed c++ dll error
- groupbox显示互斥问题
- 对象序列化问题急救!大虾来帮忙!
- [DataTable中针对某一列进行拆分并排序]
http://msdn.microsoft.com/en-us/library/aa327576(v=VS.71).aspx
{
Graphics g = pictureBox1.CreateGraphics(); string str = "这段文字右对齐"; Font font=this.Font; SizeF size = g.MeasureString(str, font); g.DrawString(str, font, new SolidBrush(Color.Black), pictureBox1.Width - size.Width, 10); g.Dispose();
}
{
using (Graphics g = this.CreateGraphics())
{
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Far;
g.DrawString("窗体[右对齐]显示文本", this.Font, Brushes.Black, ClientRectangle, format);
format.Alignment = StringAlignment.Near;
g.DrawString("窗体[左对齐]显示文本", this.Font, Brushes.Black, ClientRectangle, format);
format.Alignment = StringAlignment.Center;
g.DrawString("窗体[中置]对齐显示文本", this.Font, Brushes.Black, ClientRectangle, format);
}
}
{
using (Graphics g = this.CreateGraphics())
{
StringFormat format = new StringFormat();
format.LineAlignment = StringAlignment.Center;//垂直方向水平中置
format.LineAlignment = StringAlignment.Near;//顶部对齐
format.LineAlignment = StringAlignment.Far;//靠近底部
format.Alignment = StringAlignment.Far;
g.DrawString("窗体[右对齐]显示文本", this.Font, Brushes.Black, ClientRectangle, format);
format.Alignment = StringAlignment.Near;
g.DrawString("窗体[左对齐]显示文本", this.Font, Brushes.Black, ClientRectangle, format);
format.Alignment = StringAlignment.Center;
g.DrawString("窗体[中置]对齐显示文本", this.Font, Brushes.Black, ClientRectangle, format);
}
}
本人但凡一看到一个解决问题的方法就速度结贴了,呵呵,sorry~~~