winfrom專案的窗體與窗體中控制項等比例縮放問題

2021-10-10 12:56:42 字數 1204 閱讀 8417

先編寫類

//***控制控制項大小及文字大小的開始***//

public void settag(control cons)//記錄控制項集初始的 位置、 大小、 字型大小資訊 }}

public void setcontrols(float newx, float newy, control cons)//重新調整控制項的位置、大小、字型大小

);float a = convert.tosingle(mytag[0]) * newx;

con.width = (int)(a);

a = convert.tosingle(mytag[1]) * newy;

con.height = (int)(a);

a = convert.tosingle(mytag[2]) * newx;

con.left = (int)(a);

a = convert.tosingle(mytag[3]) * newy;

con.top = (int)(a);

single currentsize = convert.tosingle(mytag[4]) * math.min(newx, newy);

con.font = new font(con.font.name, currentsize, con.font.style, con.font.unit);

if (con.controls.count > 0)//處理子控制項

}}

再在窗體載入事件中寫入

change changes = new change();//例項化物件

this.resize += new eventhandler(form_resize);//在改變窗體大小時呼叫方法form_resize

x = this.width;//獲取窗體寬度

y = this.height;//獲取窗體高度

changes.settag(this);//使用change類中的settag方法,並傳值

form_resize(new object(), new eventargs());

宣告全域性變數

private float x;//私有變數存寬度

private float y;//私有變數存高度

宣告全域性方法

void form_resize(object sender, eventargs e)

}

winfrom父子窗體傳值

父窗體向子窗體傳值 例項化子窗體時傳參到子窗體建構函式,子窗體可在建構函式中取到param 子窗體向父窗體傳值 子窗體定義委託 定義事件 子窗體觸發事件並傳入引數 父窗體註冊子窗體事件處理函式 父窗體事件處理函式中接收到子窗體引數 父窗體 private void button1 click obj...

winfrom建立轉圈等待窗體

第一步 建立乙個waitform public partial class waitform form public color circlecolor set public float circlesize set public bitmap drawcircle int j for int i ...

Winfrom中窗體的傳值

常用方法 1.靜態變數 在窗體裡class from1中,寫入乙個靜態變數a,可以給其賦值,那麼在這個專案中,就可以通過from.a來呼叫。不推薦此種方法,不太安全。2.比較穩妥的方法,就是在傳值的過程中,首先在被傳值窗體from2中,建立乙個共有屬性b,作為接受者。在from1裡例項from2時,...