Hi,
ich habe ein Panel, in das ich je nach Benutzereingabe mal mehr oder weniger zeichnen. deshalb wollte ich mittels Autoscroll(falls nötig) einen Scrollbar anzeigen lassen.
Allerdings habe ich festgestellt, dass der nur angezeigt wird, wenn ich Controls in das Panel schiebe. Zeichnen reicht nicht!
Wie kann ich das umgehen?
MfG ThePaul
Hallo thepaul,
zu 1. Wenn ich das richtig in Erinnerung habe mit Panel.AutoScrollMinSize. Es geht jedenfalls über irgendeine Property.
zu 2. Panel.AutoScrollPosition
herbivore
danke für die super schnelle antwort.
zu 1.: die Eigenschaft hilft mir nicht. Hat noch jemand ne Idee welche Eigenschaft das sein könnte
zu 2.: Was für einen Punkt muss da übergeben?
Hallo thepaul,
zu 1. Panel.AutoScrollMinSize ist das richtige. Ich habe es jetzt probiert.
zu 2. ScrollableControl.AutoScrollPosition
herbivore
nach langer zeit nochmal ich!
ich habe nochmal ausführlich probiert, bei mir geht es aber immer noch nicht.
Mein Code (einfach ein neues Formular erstellen, ein Button und ein Panel drauf und bei dem Panel Autosize auf true):
for (int i = 0; i < 10; i++)
{
Graphics g = panel1.CreateGraphics();
//Mit Zeichnen Gehts nicht :(
//g.FillRectangle(new SolidBrush(Color.DarkCyan), 10, i * 100 + 10, 100, 90);
//Mit Button gehts
Button b = new Button();
b.Text = i.ToString();
b.Location = new Point(10, i * 100 + 10);
b.Size = new Size(100, 90);
panel1.Controls.Add(b);
}
Hallo thepaul,
vielleicht hilft dir:
using System;
using System.IO;
using System.Windows.Forms;
using System.Drawing;
public class MyWindow : Form
{
const int iWidth = 600;
const int iHeight = 480;
public MyWindow ()
{
Control ctrlCurr;
Text = "MyWindow";
ClientSize = new Size (iWidth, iHeight);
ctrlCurr = new Panel ();
ctrlCurr.Dock = DockStyle.Fill;
((Panel)ctrlCurr).AutoScroll = true;
((Panel)ctrlCurr).AutoScrollMinSize = new Size (3*iWidth, 3*iHeight);
ctrlCurr.Paint += PanelPaint;
Controls.Add (ctrlCurr);
}
protected void PanelPaint (Object objSender, PaintEventArgs e)
{
Panel pnl = ((Panel)objSender);
Console.WriteLine (e.ClipRectangle);
Console.WriteLine (((Panel)objSender).AutoScrollPosition);
e.Graphics.FillEllipse (Brushes.Green,
10+pnl.AutoScrollPosition.X,
10+pnl.AutoScrollPosition.Y,
iWidth / 2, iHeight / 2);
}
}
static class App
{
public static void Main (string [] astrArg)
{
Application.Run (new MyWindow ());
}
}
herbivore
PS: Man muss die AutoScrollPosition natürlich nicht überall einzeln hinzuaddieren, sondern kann stattdessen auch einmal vornweg
e.Graphics.TranslateTransform (pnl.AutoScrollPosition.X, pnl.AutoScrollPosition.Y);
benutzen.
Suchhilfe: 1000 Worte