解决方案 »
- 50分 只有这么多了求C# 发送邮件的程序
- dgvClass.DataSource=ds.Tables[0]中的参数0是什么意思?
- 谁能解释一下winform连接数据库的思路?
- 用了异步调用,UI线程仍然100%!
- C# 和 C++ 高手速进 有关程序剪贴板问题
- 再遇WinForm获取网页内容时的难题
- 有无去 GrapeCity 葡萄城应聘的,或者在那里工作的兄弟,介绍一下这个公司如何?
- 问一个服务器控件问题
- 在Winform中,我选中窗体上的textBox或datagrid改变其字体的大小应该如何做?
- wpf Webbrowser 多点触摸问题
- 求个正则表达式~~~~
- 怎么移除Datagrid里面的某行
不过自己也可以在窗体中的 Resize 事件中去写代码,
一旦检测到窗体的大小有变化,窗体字体的大小就作相应的变化
?
不写这个的话控件是不会随着像素变化而变化的。现在只是控件变了而字体没有随着控件变化
我现在进行调试是使用下面控件占窗口比例来算的
factor[i++] = (ctr.Location.X) / (float)Size.Width;
结果字不够大。我把字放大了两倍结果效果看上去不错,这样的话现在我想问下font.size这个属性的大小到底是怎么算的啊
这个是基本的图像的样子。我需要知道这个字体是怎么算的才能知道重新求,就好像control中的location那个是定位一样,字体估计也有定位的。。font定位之后的size也没有height和width这样的东西。所以没法像control中的控件的size来改变。
备注
首选使用 Layout 事件处理自定义布局。响应 Resize 事件时会引发 Layout 事件,但在其他可能需要应用布局的情况下也会引发此事件。如果通过编程修改或用户交互更改 Size 属性,则将引发此事件。有关处理事件的更多信息,请参见使用事件。示例
下面的代码示例演示 SizeChanged 事件。该示例中提供了 Button 控件的一个实例,此实例既可以水平缩放,也可以垂直缩放。 NumericUpDown 实例提供了水平比例因子和垂直比例值。名为“OK”的 Button 实例用于设置 Button 控件实例的比例值。只要控件大小更改,就会调用与控件的 SizeChanged 事件关联的事件处理程序。该事件处理程序显示一个消息框,指示控件的大小已更改。
例如这个“好”字。在电脑上面是怎么写出来的
像是控件就是先用location确定起始坐标点然后用height和width来确定控件的大小的
求高手讲解。
{
public Form7()
{
InitializeComponent();
} private void button1_SizeChanged(object sender, EventArgs e)
{
Font font = new Font(button1.Font.FontFamily,button1.Height * 0.5f);
button1.Font = font;
}
}
partial class Form7
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows Form Designer generated code /// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.button1.Location = new System.Drawing.Point(61, 61);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(192, 48);
this.button1.TabIndex = 0;
this.button1.Text = "按钮";
this.button1.UseVisualStyleBackColor = true;
this.button1.SizeChanged += new System.EventHandler(this.button1_SizeChanged);
//
// Form7
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 186);
this.Controls.Add(this.button1);
this.Name = "Form7";
this.Text = "Form7";
this.ResumeLayout(false); } #endregion private System.Windows.Forms.Button button1;
你的这个第二个参数为什么是0.5f。我知道这个构造我也能写出你的代码,我的意思是自动调节font的大小。
你如果是写控件的自动调节不是用location得到控件的起始点。然后用height和width来确定大小吗
font这个是怎么来确定大小的我又不是要一个固定的大小。固定大小我直接用控件里的font属性改不更好
但是你做的Font font = new Font(button1.Font.FontFamily,button1.Height * 0.5f);中的
button1.Height*0.5f是什么意思??
这个我要改变图形的大小,在panel中写的话和你是不一样的。所以我想知道你这个0.5f是什么意思
ctrl.Font=new Font(this.Font.Name,(ctrl.Height*scale[i++]));我是直接成比例系数,但是这个比例系数我找了半天没找到怎么算,都不太好
在分辨率为96PX/英寸的显示器下,高度乘以0.5约是,字体高度占空间高度的65%
比如同样的字体绘制“as”和“asdfghjkl”你说宽度能一样么,所以指定字体的宽度没有任何意义。
你选择了一种字体后,按指定字号绘制的文本的宽度就定死了,可以扩展一个方法private SizeF GetTextBounds(Font font,string txt)
{
Bitmap bmp = new Bitmap(1,1);
using(Graphics g = Graphics.FromImage(bmp))
{
SizeF size = g.MeasureString(font,txt);
return size;
}
}手敲的,可能有些错误,自己修正下。