c# - Use same code on another button -
i'm using exact same code multiple times , thought quite inefficient copy/paste everything. there way let's button2 use exact same code button1 without copy/pasting everything?
some of code big, that's why i'm asking.
i'm aware of example:
private tabpage t { { return (t.selectedtab); } }
however have no idea how make work this: (yes, there multiple ways enable full screen mode in application)
if (formborderstyle != formborderstyle.none) { formborderstyle = formborderstyle.none; windowstate = formwindowstate.normal; windowstate = formwindowstate.maximized; p1.backcolor = color.white; p2.backcolor = color.white; topmost = true; c2.visible = false; wi.visible = false; t1.visible = false; f.text = "exit full screen"; t2.text = "exit full screen"; } else { formborderstyle = formborderstyle.sizable; if (environment.osversion.version.build >= 7000) { if (dwm.dwmiscompositionenabled()) { color c = color.fromargb(255, 221, 220, 220); transparencykey = c; p1.backcolor = c; p2.backcolor = c; margins mr = new margins(); mr.t = 1800; intptr h = handle; int result = dwmextendframeintoclientarea(h, ref mr); } } topmost = false; wi.visible = true; t1.visible = true; f.text = "full screen"; t2.text = "full screen"; }
just apply same event handler both buttons. can done either through typing name of method in events tab of designer, or through manually adding event handler upon construction.
it's idea in such cases refactor method name makes sense both buttons call. if clicking button2
fires button1_click
other coders might confused. if both buttons fire makefullscreen
method it's less confusing.
Comments
Post a Comment