您好我想要實現一個窗體,使用編碼調整大小。我使用form_paint方法繪製邊框,但是我無法「繪製」這個邊框。我打算做的事情是,當我調整窗體大小時使用「平滑調整大小」的定時器,窗體邊框將隨着調整大小一起更新。我該怎麼辦?在Winforms中繪製圖形繪製
Pen setupControlPen = new Pen(SystemColors.Control, 16);
Pen setupDimGrayPen = new Pen(Color.DimGray, 5);
我form_paint內://繪製一個表格邊框
Rectangle newRectangle;
newRectangle = new Rectangle(new Point(0, 0), new Size(this.Width - 1, this.Height - 1));
setupGraphics.DrawRectangle(setupDimGrayPen, newRectangle);
click事件中://我試圖繪製在已經劃定的邊界。
Rectangle newRectangle = new Rectangle(new Point(0, 0), new Size(this.Width - 1, this.Height - 1));
setupGraphics.DrawRectangle(setupControlPen, newRectangle);
謝謝!
更新:我試圖使用resize_form事件和計時器重繪,但仍然不能重新繪製邊界,每當我調整窗體大小。
更新2:覆蓋方法的作品!關於setupGraphics:
//global space
Graphics setupGraphics;
//form_load
setupGraphics = this.CreateGraphics();
//so whenever I want to draw something during an event, supposing a button click event to draw a line:
setupGraphics.DrawLine(pen, point1, point2);
我想問一下這個方法是否有缺陷?或者應該在form_paint方法內完成所有事情?
你的FormBorderStyle設置爲None嗎? – LarsTech
是的,它被設置爲none – user776914