前提・実現したいこと
動的に作成したPanelに対して、ウィンドウのサイズが変わったらイベントを開始し
ウィンドウのサイズに合わせPanelのサイズを変えることは可能でしょうか。
可能であれば、どのような命令を使えばいいか教えていただけると幸いです。
該当のソースコード
C#
1 public partial class Form1 : Form 2 { 3 Panel Panel_Main; 4 Panel Panel_Sub_Left; 5 Panel Panel_Sub_Right; 6 Graphics g; 7 int x = -1; 8 int y = -1; 9 bool Moving = false; 10 Pen pen; 11 12 public Form1() 13 { 14 InitializeComponent(); 15 Setting(); 16 } 17 18 private void Form1_Load(object sender, EventArgs e) 19 { 20 this.Width = Screen.PrimaryScreen.WorkingArea.Width; 21 this.Height = Screen.PrimaryScreen.WorkingArea.Height; 22 this.DesktopLocation = new Point(0, 0); 23 } 24 private void Create_MainPanel() 25 { 26 Panel_Main = new Panel(); 27 Panel_Main.Location = new Point(250, 50); 28 Panel_Main.Size = new Size((Screen.PrimaryScreen.WorkingArea.Width * 74) / 100, Screen.PrimaryScreen.WorkingArea.Height - 100); 29 Panel_Main.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; 30 this.Controls.Add(Panel_Main); 31 Panel_Main.MouseDown += new MouseEventHandler(this.Panel_MouseDown); 32 Panel_Main.MouseUp += new MouseEventHandler(this.Panel_MouseUp); 33 Panel_Main.MouseMove += new MouseEventHandler(this.Panel_MouseMove); 34 } 35 private void Create_SubPanel_1() 36 { 37 Panel_Sub_Left = new Panel(); 38 Panel_Sub_Left.Location = new Point(20, 50); 39 Panel_Sub_Left.Size = new Size((Screen.PrimaryScreen.WorkingArea.Width * 10) / 100, Screen.PrimaryScreen.WorkingArea.Height - 100); 40 Panel_Sub_Left.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; 41 this.Controls.Add(Panel_Sub_Left); 42 } 43 private void Create_SubPanel_2() 44 { 45 Panel_Sub_Right = new Panel(); 46 Panel_Sub_Right.Location = new Point((Screen.PrimaryScreen.WorkingArea.Width * 885) / 1000, 50); 47 Panel_Sub_Right.Size = new Size((Screen.PrimaryScreen.WorkingArea.Width * 10) / 100, Screen.PrimaryScreen.WorkingArea.Height - 100); 48 Panel_Sub_Right.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; 49 this.Controls.Add(Panel_Sub_Right); 50 } 51 private void Setting() 52 { 53 Create_MainPanel(); 54 Create_SubPanel_1(); 55 Create_SubPanel_2(); 56 g = Panel_Main.CreateGraphics(); 57 g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; 58 pen = new Pen(Color.Black, 5); 59 pen.StartCap = pen.EndCap = System.Drawing.Drawing2D.LineCap.Round; 60 } 61 private void Panel_MouseDown(object sender, MouseEventArgs e) 62 { 63 Moving = true; 64 x = e.X; 65 y = e.Y; 66 } 67 private void Panel_MouseUp(object sender, MouseEventArgs e) 68 { 69 Moving = false; 70 x = -1; 71 y = -1; 72 } 73 private void Panel_MouseMove(object sender, MouseEventArgs e) 74 { 75 if(Moving && x != -1 && y != -1) 76 { 77 g.DrawLine(pen, new Point(x, y), e.Location); 78 x = e.X; 79 y = e.Y; 80 } 81 } 82 }
Panel の Anchor プロパティでは役に立たないということですか?
回答2件
あなたの回答
tips
プレビュー