using System; using System.Windows.Forms; using System.Drawing; public partial class MyForm : Form { [System.STAThread] // Main の直前にこれがないとなぜか日本語入力とかできない! static void Main() { // Main: プログラムが始まる特別なメソッド名 Application.Run(new MyForm()); } // ==================================================================================== Color bk=Color.FromArgb(0,0,0), yw=Color.FromArgb(255,255,140), gr=Color.FromArgb(220,220,140); int xb=10, xc=100; Scroll hsc1=new Scroll(); TextBox textrealbase=new TextBox(), textmechanicalbase=new TextBox(); CheckBox cbfeedback = new CheckBox(); Scroll scbase=new Scroll(), scwhole=new Scroll(), scview=new Scroll(), sclargechange=new Scroll(), scw=new Scroll(), sch=new Scroll(), sclocx=new Scroll(), sclocy=new Scroll(); TextBox textbase, textwhole, textview, textlargechange, textw, texth, textlocx, textlocy; CheckBox cbinverse = new CheckBox(); Label createlabel(int x, int y, string str) { return createlabel(x, y, str, 120); } // ==================================================================================== Label createlabel(int x, int y, string str, int w) { Label label=new Label(); label.SetBounds(x, y, w, 20); label.Text = str; Controls.Add(label); return label; } // ==================================================================================== public MyForm ( ) { this.Text = "Scroll Demo"; // タイトルバーに入れる文字を指定 this.Size = new Size(660, 600); this.Location = new Point(50, 50); // this.BackColor = Color.LightGreen; this.FormBorderStyle = FormBorderStyle.Sizable; DoubleBuffered = true; // hsc1.BaseChangedAnyway += (o, n)=>{ var L=hsc1.getbase(); textrealbase.Text=L.ToString(); changedanyway(); }; hsc1.BaseChangedMechanical += (o,n)=>{ var L=hsc1.getbase(); textmechanicalbase.Text=L.ToString(); if (cbfeedback.Checked) { scbase.setbase(L); } }; Controls.Add(hsc1); // createlabel(40, 120, "real base", 60); textrealbase.SetBounds(110, 120, 60, 15); // realbase textrealbase.Text="0"; createlabel(200, 120, "mechanical base", 100); textmechanicalbase.SetBounds(320, 120, 60, 15); textmechanicalbase.Text="0"; cbfeedback.SetBounds(460, 120, 250, 15); cbfeedback.Text = "feedback"; cbfeedback.Checked = true; Controls.Add(textrealbase); Controls.Add(textmechanicalbase); Controls.Add(cbfeedback); // int xlabels=40, xscrs = 220, xtexts = 500, ys = 160; // textbase = new TextBox(); scbase.setwhole(2500); scbase.SetBounds(xscrs, ys, 250, 20); scbase.BaseChangedAnyway += (o,e) =>{ textbase.Text=e.ToString(); hsc1.setbase(e); changedanyway(); }; scbase.setbase(0); createlabel(xlabels, ys, "base(not always valid)"); textbase.SetBounds(xtexts, ys, 60, 20); Controls.Add(scbase); Controls.Add(textbase); ys += 40; // scwhole.setwhole(2500); textwhole = new TextBox(); scwhole.SetBounds(xscrs, ys, 250, 20); scwhole.BaseChangedAnyway += (o,e)=>{ textwhole.Text=e.ToString(); xc=e/5; hsc1.setwhole(e); changedanyway(); }; scwhole.setbase(500); createlabel(xlabels, ys, "whole"); textwhole.SetBounds(xtexts, ys, 60, 20); ys += 40; Controls.Add(scwhole); Controls.Add(textwhole); // scview.setwhole(1000); textview = new TextBox(); scview.SetBounds(xscrs, ys, 140, 20); scview.BaseChangedAnyway += (o,e) =>{ textview.Text=e.ToString(); xb=e/5; hsc1.setview(e); changedanyway(); }; scview.setbase(50); createlabel(xlabels, ys, "view"); textview.SetBounds(xtexts, ys, 60, 20); ys += 40; Controls.Add(scview); Controls.Add(textview); // sclargechange.setwhole(1000); textlargechange = new TextBox(); sclargechange.SetBounds(xscrs, ys, 140, 20); sclargechange.BaseChangedAnyway += (o,e)=>{ textlargechange.Text=e.ToString(); hsc1.setlargeChange(e); }; sclargechange.setbase(100); createlabel(xlabels, ys, "largeChange"); textlargechange.SetBounds(xtexts, ys, 60, 20); ys += 40; Controls.Add(sclargechange); Controls.Add(textlargechange); // scw.setwhole(1400); textw = new TextBox(); scw.SetBounds(xscrs, ys, 250, 20); scw.BaseChangedAnyway += (o,e)=>{ textw.Text=e.ToString(); hsc1.setw(e); }; scw.setbase(300); createlabel(xlabels, ys, "visual width"); textw.SetBounds(xtexts, ys, 60, 20); ys += 40; Controls.Add(scw); Controls.Add(textw); // sch.setwhole(1400); texth = new TextBox(); sch.SetBounds(xscrs, ys, 250, 20); sch.BaseChangedAnyway += (o,e)=>{ texth.Text=e.ToString(); hsc1.seth(e); }; sch.setbase(20); createlabel(xlabels, ys, "visual height"); texth.SetBounds(xtexts, ys, 60, 20); ys += 40; Controls.Add(sch); Controls.Add(texth); // sclocx.setwhole(600); textlocx = new TextBox(); sclocx.SetBounds(xscrs, ys, 250, 20); sclocx.BaseChangedAnyway += (o,e)=>{ textlocx.Text=e.ToString(); hsc1.setx(50+e); }; sclocx.setbase(0); createlabel(xlabels, ys, "visual location_x"); textlocx.SetBounds(xtexts, ys, 60, 20); ys += 40; Controls.Add(sclocx); Controls.Add(textlocx); // sclocy.setwhole(600); textlocy = new TextBox(); sclocy.SetBounds(xscrs, ys, 250, 20); sclocy.BaseChangedAnyway += (o,e)=>{ textlocy.Text=e.ToString(); hsc1.sety(90+e); }; sclocy.setbase(0); createlabel(xlabels, ys, "visual location_y"); textlocy.SetBounds(xtexts, ys, 60, 20); ys += 40; Controls.Add(sclocy); Controls.Add(textlocy); // cbinverse.Text = "inversed direction"; cbinverse.SetBounds(180, ys, 160, 20); cbinverse.CheckedChanged+= (o,e)=>{ hsc1.setinverse(cbinverse.Checked); }; Controls.Add(cbinverse); Refresh(); } // ==================================================================================== void changedanyway(){ Refresh(); } // ==================================================================================== bool firsttime = true; public int iactive = 0; protected override void OnActivated(EventArgs e) { if (firsttime) { OnSizeChanged(null); firsttime = false; } } // ==================================================================================== protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; for (var i=0; i<=2500; i+=500) { var ix=getix(i); g.DrawLine(new Pen(bk), ix, 48, ix, 58); if (i == 0) {ix += 8; } g.DrawString(i.ToString(), Font, new SolidBrush(bk), ix-12, 70); } int x0=getix(0), xv=getix(hsc1.getbase()); g.FillRectangle(new SolidBrush(yw), x0,10,xc,30); g.DrawRectangle(new Pen(bk), xv,10,xb,30); } // ==================================================================================== int getix(int x) { return 50+(x/5); } // ==================================================================================== } // ########################################################################################