本文整理汇总了C#中System.Windows.Forms.Label.CreateGraphics方法的典型用法代码示例。如果您正苦于以下问题:C# Label.CreateGraphics方法的具体用法?C# Label.CreateGraphics怎么用?C# Label.CreateGraphics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Label
的用法示例。
在下文中一共展示了Label.CreateGraphics方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
public void Init()
{
Label l = new Label();
this.graphics = l.CreateGraphics();
section = new BaseSection();
section.Location = new Point (50,50);
section.Size = new Size(400,200);
}
示例2: AjustarTamanhoFonte
private void AjustarTamanhoFonte(Label label)
{
Graphics graphics = label.CreateGraphics();
SizeF textSize = graphics.MeasureString(label.Text, label.Font);
float falta = textSize.Width + 100 - label.Width;
if (falta > 0)
label.Font = new Font(label.Font.FontFamily, label.Font.Size - Math.Abs(falta) / 200, FontStyle.Bold);
}
示例3: adjustLabelSize
private void adjustLabelSize(Label label)
{
string text = label.Text;
Graphics g = label.CreateGraphics();
SizeF oSize = g.MeasureString(text, label.Font);
int nWidth = (int)oSize.Width + 5;
int nHeight = 20;
label.Width = nWidth;
label.Height = nHeight;
}
示例4: InitBorderTitle
public static void InitBorderTitle(this Control ctrl, Window window, Control child)
{
if (window is ActiveWindow)
{
ActiveWindow wnd = (ActiveWindow)window;
if (ctrl.Controls.ContainsKey("LabelTitle")) ctrl.Controls.RemoveByKey("LabelTitle");
if (wnd.BorderVisible)
{
ctrl.SuspendLayout();
child.SuspendLayout();
child.Left += wnd.BorderWidth;
child.Width -= wnd.BorderWidth << 1;
child.Height -= wnd.BorderWidth;
System.Windows.Forms.Label title = new System.Windows.Forms.Label();
title.AutoSize = false;
title.Name = "LabelTitle";
title.BackColor = wnd.BorderColorFrienly;
title.Font = new Font(wnd.TitleFont, wnd.TitleSize);
title.ForeColor = wnd.TitleColorFrienly;
title.Text = wnd.TitleText;
title.Left = wnd.BorderWidth;
title.Top = 0;
using (Graphics g = title.CreateGraphics())
{
title.Size = g.MeasureString(wnd.TitleText, title.Font).ToSize();
}
title.Width = child.Width;
title.AutoEllipsis = true;
title.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
ctrl.Controls.Add(title);
if (title.Height == 0)
{
child.Top += wnd.BorderWidth;
child.Height -= wnd.BorderWidth;
}
else
{
child.Top += title.Height;
child.Height -= title.Height;
}
ctrl.BackColor = wnd.BorderColorFrienly;
child.ResumeLayout();
ctrl.ResumeLayout();
title.Invalidate();
}
ctrl.Text = wnd.TitleText;
}
}
示例5: InvoiceControl_Load
private void InvoiceControl_Load( object sender, EventArgs e )
{
if( invoice == null ) {
return;
}
lblName.Text = string.Format( "{0}, {1}, {2} kr", invoice.Name, invoice.Date.ToString( "yyyy-MM-dd" ), invoice.Amount );
int y = 0;
if( !string.IsNullOrEmpty( invoice.Comment ) ) {
using( Font font = new Font( "Microsoft Sans Serif", 8, FontStyle.Italic ) ) {
Label l = new Label { Text = invoice.Comment, Top = y, Left = 10, Font = font, AutoSize = true, Width = pnlPayments.Width - 5, Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right };
using( Graphics gr = l.CreateGraphics() ) {
SizeF measureString = gr.MeasureString( invoice.Comment, font );
l.Height = (int)(measureString.Height + 5);
}
pnlPayments.Controls.Add( l );
y += l.Height + 5;
}
}
using( Font font = new Font( "Microsoft Sans Serif", 9 ) ) {
Label l;
foreach( InvoicePayment payment in invoice.Payments ) {
l = new Label { Text = string.Format( "{0} kr", payment.Amount ), Top = y, Left = 10, Font = font, AutoSize = true};
pnlPayments.Controls.Add( l );
l = new Label { Text = string.Format( "{0}", payment.Date.ToString( "yyyy-MM-dd" ) ), Top = y, Left = 100, Font = font, AutoSize = true };
pnlPayments.Controls.Add( l );
y += l.Height + 5;
}
if( y == 0 ) {
l = new Label { Text = "No payments found...", Top = y, Left = 10, Font = font, AutoSize = true };
pnlPayments.Controls.Add( l );
y += l.Height + 5;
}
l = new Label { Text = "Balance", Top = y, Left = 10, Font = font, AutoSize = true };
l.ForeColor = invoice.Balance <= 0 ? Color.Green : Color.Red;
pnlPayments.Controls.Add( l );
l = new Label { Text = string.Format( "{0} kr", invoice.Balance ), Top = y, Left = 100, Font = font, AutoSize = true };
l.ForeColor = invoice.Balance <= 0 ? Color.Green : Color.Red;
pnlPayments.Controls.Add( l );
y += l.Height + 5;
Button b = new Button { Top = y, Left = 15, Font = font, AutoSize = true, Text = "Add payment" };
b.Click += AddPaymentClick;
pnlPayments.Controls.Add( b );
}
}
示例6: SetLabelText
private void SetLabelText(Label label, string text)
{
if (label.Width > label.CreateGraphics().MeasureString(text+ ": " + FileDescription, label.Font).Width)
label.Text = text;
else
label.Text = Path.GetFileName(text);
if (FileDescription.Length > 0)
label.Text += ": " + FileDescription;
}
示例7: computeLabelWidth
private static int computeLabelWidth(Label l)
{
Graphics g = l.CreateGraphics();
int result = (int)g.MeasureString(l.Text, l.Font).Width + l.Margin.Horizontal;
g.Dispose();
return result;
}
示例8: FitToWidth
private void FitToWidth(Label ctrl, float maxAdjust)
{
Font retFont = (Font)ctrl.Font.Clone();
float minSize = retFont.Size - maxAdjust;
using (Graphics graphics = ctrl.CreateGraphics())
{
float textWidth = graphics.MeasureString(ctrl.Text, retFont).Width;
while (textWidth > (float)ctrl.Width && retFont.Size > minSize)
{
retFont = new Font(retFont.Name, (retFont.Size - 0.1F));
textWidth = graphics.MeasureString(ctrl.Text, retFont).Width;
}
ctrl.Font = retFont;
}
}
示例9: FormField
//.........这里部分代码省略.........
m_control = jtxt;
m_form.error.SetIconAlignment(m_control, ErrorIconAlignment.MiddleLeft);
break;
case FieldType.jid_multi:
JidMulti multi = new JidMulti();
multi.AddRange(m_val);
m_control = multi;
break;
case FieldType.Fixed:
// All of this so that we can detect URLs.
// We can't just make it disabled, because then the URL clicked
// event handler doesn't fire, and there's no way to set the
// text foreground color.
// It would be cool to make copy work, but it doesn't work for
// labels, either.
RichTextBox rich = new RichTextBox();
rich.DetectUrls = true;
rich.Text = string.Join("\r\n", f.Vals);
rich.ScrollBars = RichTextBoxScrollBars.None;
rich.Resize += new EventHandler(lbl_Resize);
rich.BorderStyle = BorderStyle.None;
rich.LinkClicked += new LinkClickedEventHandler(rich_LinkClicked);
rich.BackColor = System.Drawing.SystemColors.Control;
rich.KeyPress += new KeyPressEventHandler(rich_KeyPress);
rich.GotFocus += new EventHandler(rich_GotFocus);
rich.AcceptsTab = false;
rich.AutoSize = false;
m_control = rich;
break;
default:
TextBox txt = new TextBox();
txt.Lines = m_val;
m_control = txt;
break;
}
if (m_type != FieldType.hidden)
{
m_control.Parent = p;
if (f.Desc != null)
form.tip.SetToolTip(m_control, f.Desc);
String lblText = "";
if (f.Label != "")
lblText = f.Label + ":";
else if (f.Var != "")
lblText = f.Var + ":";
if (lblText != "")
{
m_label = new Label();
m_label.Parent = p;
m_label.Text = lblText;
if (m_required)
{
m_label.Text = "* " + m_label.Text;
m_form.error.SetIconAlignment(m_control, ErrorIconAlignment.MiddleLeft);
m_control.Validating += new CancelEventHandler(m_control_Validating);
m_control.Validated += new EventHandler(m_control_Validated);
}
Graphics graphics = m_label.CreateGraphics();
SizeF s = m_label.Size;
s.Height = 0;
int chars;
int lines;
SizeF textSize = graphics.MeasureString(m_label.Text, m_label.Font, s, StringFormat.GenericDefault, out chars, out lines);
m_label.Height = (int) (textSize.Height);
if (lines > 1)
m_label.TextAlign = ContentAlignment.MiddleLeft;
else
m_label.TextAlign = ContentAlignment.TopLeft;
m_label.Top = 0;
p.Controls.Add(m_label);
m_control.Location = new Point(m_label.Width + 3, 0);
m_control.Width = p.Width - m_label.Width - 6;
p.Height = Math.Max(m_label.Height, m_control.Height) + 4;
}
else
{
m_control.Location = new Point(0, 0);
m_control.Width = p.Width - 6;
p.Height = m_control.Height + 4;
}
m_control.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
p.Controls.Add(m_control);
p.Dock = DockStyle.Top;
m_form.pnlFields.Controls.Add(p);
if (m_form.m_type != XDataType.form)
m_control.Enabled = false;
}
}
示例10: OnClick
protected override void OnClick(EventArgs click)
{
base.OnClick(click);
if (this.m_Classrooms.Count <= 0)
return;
TCPClassroomManager manager = this.m_Classrooms[0];
if (!m_Connected) {
Form form = new Form();
form.Text = "Connect to TCP Server...";
form.ClientSize = new Size(350, form.ClientSize.Height);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
Label label = new Label();
label.Text = "Server:";
using (Graphics graphics = label.CreateGraphics())
label.ClientSize = Size.Add(new Size(10, 0),
graphics.MeasureString(label.Text, label.Font).ToSize());
label.Location = new Point(5, 5);
TextBox host = new TextBox();
host.Location = new Point(label.Right + 10, label.Top);
host.Width = form.ClientSize.Width - host.Left - 5;
Button okay = new Button();
okay.Text = Strings.OK;
okay.Width = (host.Right - label.Left) / 2 - 5;
okay.Location = new Point(label.Left, Math.Max(host.Bottom, label.Bottom) + 10);
Button cancel = new Button();
cancel.Text = Strings.Cancel;
cancel.Width = okay.Width;
cancel.Location = new Point(okay.Right + 10, okay.Top);
EventHandler connect = delegate(object source, EventArgs args) {
try {
//manager.ClientConnect(host.Text); //obsolete
this.m_Connected = true;
this.Text = "Disconnect from &TCP Server...";
form.Dispose();
}
catch (Exception e) {
MessageBox.Show(
string.Format("Classroom Presenter 3 was unable to connect to\n\n"
+ "\t\"{0}\"\n\nfor the following reason:\n\n{1}",
host.Text, e.Message),
"Connection Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
this.m_Connected = false;
}
};
host.KeyPress += delegate(object source, KeyPressEventArgs args) {
if (args.KeyChar == '\r')
connect(source, EventArgs.Empty);
};
okay.Click += connect;
cancel.Click += delegate(object source, EventArgs args) {
this.m_Connected = false;
form.Dispose();
};
form.ClientSize = new Size(form.ClientSize.Width, Math.Max(okay.Bottom, cancel.Bottom) + 5);
form.Controls.Add(label);
form.Controls.Add(host);
form.Controls.Add(okay);
form.Controls.Add(cancel);
DialogResult dr = form.ShowDialog(this.GetMainMenu() != null ? this.GetMainMenu().GetForm() : null);
}
else {
//manager.ClientDisconnect();
this.Text = "Connect to &TCP Server...";
m_Connected = false;
}
}
示例11: ChooseLabelFont
void ChooseLabelFont(Label label) {
if ((bool?)label.Tag != true)
return;
using (var g = label.CreateGraphics()) {
int sizeRatio = (int)g.MeasureString(label.Text, font).Width / GameArea.ClientSize.Width;
if (sizeRatio >= 2)
label.Font = extraSmallFont;
else if (sizeRatio >= 1)
label.Font = smallFont;
else
label.Font = font;
}
}
示例12: createLabel
private Label createLabel(string text)
{
Label lbl = new Label();
lbl.Text = text;
lbl.Width = (int)lbl.CreateGraphics().MeasureString(text, this.pnlQGroup.Font).Width + 6;
System.Windows.Forms.Padding margin = lbl.Margin;
margin.Top = 3;
margin.Right = 0;
lbl.Margin = margin;
return lbl;
}
示例13: InputBox
/// <summary>
/// Hộp thoại nhập giá trị
/// </summary>
/// <param name="promptText">Nội dung</param>
/// <param name="title">Tiêu đề</param>
/// <param name="value">Lưu giá trị người dùng nhập</param>
/// <returns>Nút người dùng bấm</returns>
private DialogResult InputBox(string promptText, string title, ref string value)
{
Form form = new Form();
Label label = new Label();
TextBox textBox = new TextBox();
Button buttonOk = new Button();
Button buttonCancel = new Button();
form.Text = title;
label.Text = promptText;
textBox.Text = value;
buttonOk.Text = "OK";
buttonCancel.Text = "Cancel";
buttonOk.DialogResult = DialogResult.OK;
buttonCancel.DialogResult = DialogResult.Cancel;
SizeF textSize = label.CreateGraphics().MeasureString(promptText, label.Font);
if (textSize.Width < 75 * 2 + 30)
textSize.Width = 75 * 2 + 10;
label.SetBounds(10, 10, (int)textSize.Width, (int)textSize.Height); //x , y , width , height
label.AutoSize = false;
textBox.SetBounds(label.Left, label.Bottom + 5, label.Width, 20);
buttonOk.SetBounds(label.Right - 75, textBox.Bottom + 5, 75, 23);
buttonCancel.SetBounds(label.Right - 75*2 - 10, textBox.Bottom + 5, 75, 23);
textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
form.ClientSize = new Size(label.Right + 10, buttonOk.Bottom + 10);
form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
//form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.StartPosition = FormStartPosition.CenterScreen;
form.MinimizeBox = false;
form.MaximizeBox = false;
form.AcceptButton = buttonOk;
form.CancelButton = buttonCancel;
DialogResult dialogResult = form.ShowDialog();
value = textBox.Text;
return dialogResult;
}
示例14: OnClick
public void OnClick(object obj, EventArgs click)
{
if (!(this.Checked)) {
if (this.m_Connected) {
using (Synchronizer.Lock(this.m_ClassroomManager.Classroom.SyncRoot))
this.m_ClassroomManager.Classroom.Connected = false;
this.Text = Strings.ConnectToTCPServer;
this.m_Connected = false;
}
return;
}
if (this.m_ClassroomManager == null)
return;
using (Synchronizer.Lock(this.m_Model.ViewerState.SyncRoot)) {
this.m_Model.ViewerState.ManualConnectionButtonName = this.Text;
}
if (this.m_Connected) {
using (Synchronizer.Lock(this.m_ClassroomManager.Classroom.SyncRoot))
this.m_ClassroomManager.Classroom.Connected = false;
this.Text = Strings.ConnectToTCPServer;
this.m_Connected = false;
}
Label label = new Label();
label.FlatStyle = FlatStyle.System;
label.Font = Model.Viewer.ViewerStateModel.StringFont2;
label.Text = Strings.ServerNameAddress;
using (Graphics graphics = label.CreateGraphics())
label.ClientSize = Size.Add(new Size(10, 0),
graphics.MeasureString(label.Text, label.Font).ToSize());
label.Location = new Point(5, 5);
Form form = new Form();
form.Font = Model.Viewer.ViewerStateModel.FormFont;
form.Text = Strings.ConnectToTCPServer;
form.ClientSize = new Size(label.Width * 3, 2 * form.ClientSize.Height);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
TextBox addressInput = new TextBox();
addressInput.Font = Model.Viewer.ViewerStateModel.StringFont2;
addressInput.Size = new Size(((int)(form.ClientSize.Width - (label.Width * 1.2))), this.Font.Height);
addressInput.Location = new Point(((int)(label.Right * 1.1)), label.Top);
using (Synchronizer.Lock(this.m_Model.ViewerState.SyncRoot)) {
if (this.m_Model.ViewerState.TCPaddress != "" && this.m_Model.ViewerState.TCPaddress.Length != 0) {
string addr = this.m_Model.ViewerState.TCPaddress;
addressInput.Text = addr;
}
}
Label label2 = new Label();
label2.FlatStyle = FlatStyle.System;
label2.Font = Model.Viewer.ViewerStateModel.StringFont2;
label2.Text = Strings.Port + " (default: " + TCPServer.DefaultPort.ToString() + ")";
using (Graphics graphics = label.CreateGraphics())
label2.ClientSize = Size.Add(new Size(10, 0),
graphics.MeasureString(label2.Text, label2.Font).ToSize());
label2.Location = new Point(5, Math.Max(addressInput.Bottom, label.Bottom) + 10);
TextBox portInput = new TextBox();
portInput.Font = Model.Viewer.ViewerStateModel.StringFont2;
portInput.Size = new Size((4 / 3) * sizeConst, sizeConst / 2);
portInput.Location = new Point(addressInput.Left, label2.Top);
using (Synchronizer.Lock(this.m_Model.ViewerState.SyncRoot)) {
if (this.m_Model.ViewerState.TCPport != 0) {
portInput.Text = this.m_Model.ViewerState.TCPport.ToString();
}
else {
portInput.Text = TCPServer.DefaultPort.ToString();
}
}
Button okay = new Button();
okay.FlatStyle = FlatStyle.System;
okay.Font = Model.Viewer.ViewerStateModel.StringFont;
okay.Text = Strings.OK;
okay.Width = (addressInput.Right - label.Left) / 2 - 5;
okay.Location = new Point(label.Left, Math.Max(portInput.Bottom, label2.Bottom) + 10);
Button cancel = new Button();
cancel.FlatStyle = FlatStyle.System;
cancel.Font = Model.Viewer.ViewerStateModel.StringFont;
cancel.Text = Strings.Cancel;
cancel.Width = okay.Width;
cancel.Location = new Point(okay.Right + 10, okay.Top);
EventHandler connect = delegate(object source, EventArgs args) {
string address = addressInput.Text;
using (Synchronizer.Lock(this.m_Model.ViewerState.SyncRoot)) {
this.m_Model.ViewerState.TCPaddress = address;
}
try {
IPAddress ipaddress;
if (!IPAddress.TryParse(address, out ipaddress)) {
//.........这里部分代码省略.........
示例15: getKeyLabel
private Label getKeyLabel(String key)
{
Label newLabel = new Label();
Boolean isText = true;
if (!key.Equals("+"))
{
newLabel.BackColor = System.Drawing.Color.White;
newLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
switch (key)
{
case "UP":
newLabel.Image = global::ACPAddIn.Properties.Resources.up;
isText = false;
break;
case "DOWN":
newLabel.Image = global::ACPAddIn.Properties.Resources.down;
isText = false;
break;
case "LEFT":
newLabel.Image = global::ACPAddIn.Properties.Resources.left;
isText = false;
break;
case "RIGHT":
newLabel.Image = global::ACPAddIn.Properties.Resources.right;
isText = false;
break;
case "COMMA":
newLabel.Text = "<";
break;
case "PERIOD":
newLabel.Text = ">";
break;
default:
newLabel.Text = key;
break;
}
int width=22;
if (isText)
{
Graphics g = newLabel.CreateGraphics();
width = (int)g.MeasureString(newLabel.Text, newLabel.Font).Width;
g.Dispose();
width += 5;
}
// Make the label a square if the width is too small
if (width < 26)
{
width = 26;
}
newLabel.Size = new System.Drawing.Size(width, 26);
newLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
}
else
{
newLabel.Size = new System.Drawing.Size(10, 26);
newLabel.Text = key;
newLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
}
return newLabel;
}