笔记7:winfrom的一些知识点(一)

一、MDI窗体

        private void 添加窗体ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 frm1 = new Form2();
frm1.MdiParent = this;
frm1.Show();
Form3 frm2 = new Form3();
frm2.MdiParent = this;
frm2.Show();
}
private void 横向排列ToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.TileHorizontal);
}
private void 纵向排列ToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.TileVertical);
}

二、字符串的截取

       //截取字符串:Text.Substring(1),截取第一个字符后面的所有
// Text.Substring(1,2),截取第一个字符后面的的两个字符
private void timer1_Tick(object sender, EventArgs e)
{
l1.Text = l2.Text = l1.Text.Substring(1) + l2.Text.Substring(0, 1);
l4.Text = l3.Text = l3.Text.Substring() + l3.Text.Substring(, );
}

三、播放音乐

             using System.Media;     //导入
SoundPlayer muise = new SoundPlayer();
muise.SoundLocation = @"..\..\1.wav"; //路径
muise.Play();

四、获取时间

         private void timer2_Tick(object sender, EventArgs e)
{
label5.Text = DateTime.Now.ToString();//显示为:2016-04-16 11:59:36
int h = DateTime.Now.Hour; //小时
int m = DateTime.Now.Minute;//分钟
int s = DateTime.Now.Second;//秒
}

五、坐标

          //this.ClientSize.Height       主窗体高度
//btnDui.ClientSize.Height 按钮控件高度
// x,y即可改变控件位置
//this.btnDui.Location = new System.Drawing.Point(x, y);
public int x = ; //x轴坐标
public int y = ; //y轴坐标
private void btnS_Click(object sender, EventArgs e)
{
if (this.ClientSize.Height - y - btnDui.ClientSize.Height <= )
{
MessageBox.Show("移到底了!");
return;
}
else
{
y += ;
this.btnDui.Location = new System.Drawing.Point(x, y);
}
}     //另外补充

        this.btnDui.BackColor = System.Drawing.Color.Green;//改变按钮的背景色
        int h=this.btnDui.Size.Height;            //获取按钮高度
        string a=Convert.ToString( h );
        MessageBox.Show(a);

上一篇:iOS 获取当前月份的天数(转)


下一篇:ECMAScript 6新特性简介