TypeScript |
The min, max size of form is fixed.
How to add possibility to scroll vertically and horizontally, so I can see everything what has been painted?
I tried for the panel : this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
and for the form:
this.AutoScrollMinSize = new Size(this.panel1.Width, this.panel1.Height);
but this isn't gonna to work, it returns size of panel before paint operation, after paint panel'll be longer.
I can set manually this.AutoScrollMinSize = new Size(999999,99999) but this is pointless too, because scrolling will be too much.
How to do it automatically, so this.AutoScrollMinSize will know what is the size of Panel after drawing, I can't do it manually because in this example I don't know how big this panel should be?
but this isn't gonna to work, it returns size of panel before paint operation, after paint panel'll be longer.
I can set manually this.AutoScrollMinSize = new Size(999999,99999) but this is pointless too, because scrolling will be too much.
How to do it automatically, so this.AutoScrollMinSize will know what is the size of Panel after drawing, I can't do it manually because in this example I don't know how big this panel should be?

jingeRank #2,527 · 554 reputationPosted Oct 24, 2009, 4:35 AM EDT
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/417a5a7f-c2db-4f88-9956-259fe27ebfa7
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 24, 2009, 4:42 AM EDT
i m also looking answer for that question but solution in not there in link you provided
jingeRank #2,527 · 554 reputationPosted Oct 24, 2009, 4:45 AM EDT
Robert9 reputationPosted Oct 24, 2009, 4:49 AM EDT
This is project http://www.sendspace.com/file/p14b5a , only form and panel and this drawing stuff.
Maximum size for form is 0;0 so you can resize it and see what have been done, but I want fixed size for form 300;300 (disallow resize), and show scrollbars vert. and horiz.
jingeRank #2,527 · 554 reputationPosted Oct 24, 2009, 4:57 AM EDT
I come up with an idea.
First create a user control in which we draw our staffs.
Note that, when you draw in the usercontrol, make sure increase the usercontrol as necessary. This might be difficult as you may need to use HitTest to make sure if the drawings are out of the usercontrol's boundary.
At last, add the usercontrol to the panel. Set AutoScroll to true.
It would be easy to say, but much hard to implement. I'm afraid.
Thank you...
Robert9 reputationPosted Oct 24, 2009, 5:42 AM EDT
Form has 300x300 fixed size, autoscrool=true and autoscrollmargin=0;0.
Panel autosize and anchor to all.
And working code:
private void panel1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Pen p1 = new Pen(Color.Black, 5); int yL = 40; float maks = 0; foreach(string ds in Enum.GetNames(typeof(DashStyle))) { if (ds != "Custom") { foreach(string lc in Enum.GetNames(typeof(LineCap))) { p1.DashStyle = (DashStyle)(Enum.Parse(typeof(DashStyle),ds)); p1.StartCap = (LineCap)(Enum.Parse(typeof(LineCap),lc)); p1.EndCap = (LineCap)(Enum.Parse(typeof(LineCap), lc)); g.DrawLine(p1, 20, yL, 120, yL); Font regFont = new Font("Arial", 10); String s = "DashStyle:"+ds+" LineCap:"+lc; SizeF sf = g.MeasureString(s, regFont); g.DrawString(s,regFont,Brushes.Black,140,yL-8); yL+=20; if (maks < sf.Width){maks = sf.Width;} } } } int yW = (int)maks + 140; this.AutoScrollMinSize= new Size(yW, yL); this.panel1.Height = yL; this.panel1.Width = yW; p1.Dispose(); } If someone has something more flexible or other idea plz answer.