|
分類:[C#]
タイマーで一定時間毎にpanelのサイズを変更するようにします。
panelにはpictureboxをドッキングしています。
タイマーをまわすとエラーが出ます。
どのようにしたらいいかいき詰まってます。
よろしくお願い致します。
namespace timer
{
public partial class Form1 : Form
{
private System.Timers.Timer m_t = null;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.PictureBox pictureBox2;
public Form1()
{
InitializeComponent();
InitializeSet();
TimerInitialize();
}
private void InitializeSet()
{
this.panel2 = new System.Windows.Forms.Panel();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.panel2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
this.SuspendLayout();
this.panel2.AutoSize = true;
this.panel2.Controls.Add(this.pictureBox2);
this.panel2.Location = new System.Drawing.Point(0, 0);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(150, 118);
this.panel2.BackColor = Color.Red;
this.panel2.TabIndex = 6;
this.panel2.TabStop = true;
this.panel2.UseWaitCursor = true;
this.pictureBox2.Dock = System.Windows.Forms.DockStyle.Left;
this.pictureBox2.Location = new System.Drawing.Point(10, 10);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(100, 118);
this.pictureBox2.BackColor = Color.Blue;
this.pictureBox2.TabIndex = 7;
this.pictureBox2.TabStop = false;
this.pictureBox2.UseWaitCursor = true;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.panel2);
this.Name = "Form1";
this.Text = "Form1";
this.panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
private void TimerInitialize()
{
this.m_t = new System.Timers.Timer();
this.m_t.Enabled = true;
this.m_t.Interval = 1000;
this.m_t.Elapsed += M_t_Elapsed;
}
private void M_t_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
this.panel2.Size = new Size(100, 100);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
}
|