第一个问题简单 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;namespace WindowsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load( object sender, EventArgs e ) { this.Opacity = 0.9; } private void button1_Click( object sender, EventArgs e ) { this.Opacity = 0.5; } } }
比如Opacity属性
---运行时还能设置?没听过
//MaximumSize = new Size(400, 400);这两个,属性设置 就是限制 窗体的大小的了。
2.AutoSizeMode属性
第二个设置Formborderstyle属性为3d或者是single,并把最大化、最小化按钮Maxminbox和MinminBox设为false,即可。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication2 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
} private void Form1_Load( object sender, EventArgs e ) {
this.Opacity = 0.9;
} private void button1_Click( object sender, EventArgs e ) {
this.Opacity = 0.5;
}
}
}
2.先禁用最大化、最小化按钮;然后拖个timer上来,设置它的事件,在cs代码中加连个属性gao,kuan,
再构造函数中获得窗体的宽和高,再在Timer_Tick事件中判断初始化的窗体大小有没有改变,有改变的话,
再把width和height还原。
private void button1_Click(object sender, EventArgs e)
{
this.Opacity = 0.6; // 60%
this.MinimizeBox = false; // 禁止最小化
this.MaximizeBox = false; // 禁止最小化
this.FormBorderStyle = FormBorderStyle.Fixed3D; // 禁止调整大小
}
{
private double opacity = 1.0;
public Form1()
{
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.FixedSingle; // 不可调整
this.MaximizeBox = false; // 无最大
this.MinimizeBox = true; // 无最小
} private void button1_Click(object sender, EventArgs e)
{ // 调整Opacity
if (opacity > 0.5)
{
opacity = opacity - 0.1;
this.Opacity = opacity;
}
else
{
opacity = 1.0;
this.opacity = opacity;
}
}
}