Button Location?

Moin, Moin.
Ich brauche ein bischen Hilfe.
Wenn Form1 startet, ist btnPanel2 oben und btnPanel3 unten.
So soll es auch sein. Und wenn ich auf den Button „Panel3“ klicke
geht dieser nach oben. Auch noch in Ordnung.
Erst wenn ich wieder auf Button „Panel2“ klicke soll Button „Panel3“ nach unten springen.
Dies soll auch funktionieren, wenn ich Form1_Resize auslöse.
Wie kann ich erreichen, das btnPanel3 (bei einem Click-Ereignis) weiß jetzt ist er oben und muß runter oder er ist unten und muß nach oben??
Kann mir jemand helfen??

MfG
Andreas

/*** Anfang ***/

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace ButtonKlick
{
///
/// Zusammendfassende Beschreibung für Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Button btnPanel2;
private System.Windows.Forms.Panel panel3;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.NumericUpDown numericUpDown1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.RadioButton radioButton1;
private System.Windows.Forms.Button btnPanel3;
///
/// Erforderliche Designervariable.
///
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Erforderlich für die Windows Form-Designerunterstützung
//
InitializeComponent();
this.panel3.Location = new System.Drawing.Point(0, this.panel2.Height-this.btnPanel3.Height);
this.panel2.Height = this.panel1.Height;
this.panel3.Height = this.panel1.Height;
//
// TODO: Fügen Sie den Konstruktorcode nach dem Aufruf von InitializeComponent hinzu
//
}

///
/// Die verwendeten Ressourcen bereinigen.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
///
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel();
this.panel3 = new System.Windows.Forms.Panel();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.btnPanel3 = new System.Windows.Forms.Button();
this.btnPanel2 = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.panel3.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
this.SuspendLayout();
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.Chartreuse;
this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.panel2});
this.panel1.Dock = System.Windows.Forms.DockStyle.Right;
this.panel1.Location = new System.Drawing.Point(40, 0);
this.panel1.Name = „panel1“;
this.panel1.Size = new System.Drawing.Size(160, 413);
this.panel1.TabIndex = 0;
//
// panel2
//
this.panel2.BackColor = System.Drawing.Color.Turquoise;
this.panel2.Controls.AddRange(new System.Windows.Forms.Control[] {
this.panel3,
this.btnPanel2,
this.groupBox1});
this.panel2.Dock = System.Windows.Forms.DockStyle.Right;
this.panel2.Name = „panel2“;
this.panel2.Size = new System.Drawing.Size(160, 413);
this.panel2.TabIndex = 0;
//
// panel3
//
this.panel3.AutoScroll = true;
this.panel3.BackColor = System.Drawing.Color.SkyBlue;
this.panel3.Controls.AddRange(new System.Windows.Forms.Control[] {
this.groupBox2,
this.btnPanel3});
this.panel3.Location = new System.Drawing.Point(0, 32);
this.panel3.Name = „panel3“;
this.panel3.Size = new System.Drawing.Size(160, 384);
this.panel3.TabIndex = 1;
//
// groupBox2
//
this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
this.radioButton1,
this.pictureBox1});
this.groupBox2.Location = new System.Drawing.Point(16, 56);
this.groupBox2.Name = „groupBox2“;
this.groupBox2.Size = new System.Drawing.Size(120, 312);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = „groupBox2“;
//
// radioButton1
//
this.radioButton1.Location = new System.Drawing.Point(40, 280);
this.radioButton1.Name = „radioButton1“;
this.radioButton1.Size = new System.Drawing.Size(32, 16);
this.radioButton1.TabIndex = 1;
this.radioButton1.Text = „radioButton1“;
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.Color.LightSkyBlue;
this.pictureBox1.Location = new System.Drawing.Point(24, 40);
this.pictureBox1.Name = „pictureBox1“;
this.pictureBox1.Size = new System.Drawing.Size(64, 40);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// btnPanel3
//
this.btnPanel3.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.btnPanel3.BackColor = System.Drawing.SystemColors.Control;
this.btnPanel3.Name = „btnPanel3“;
this.btnPanel3.Size = new System.Drawing.Size(160, 32);
this.btnPanel3.TabIndex = 0;
this.btnPanel3.Text = „Panel3“;
this.btnPanel3.Click += new System.EventHandler(this.btnPanel3_Click);
//
// btnPanel2
//
this.btnPanel2.BackColor = System.Drawing.SystemColors.Control;
this.btnPanel2.Name = „btnPanel2“;
this.btnPanel2.Size = new System.Drawing.Size(160, 32);
this.btnPanel2.TabIndex = 0;
this.btnPanel2.Text = „Panel2“;
this.btnPanel2.Click += new System.EventHandler(this.btnPanel2_Click);
//
// groupBox1
//
this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.numericUpDown1});
this.groupBox1.Location = new System.Drawing.Point(16, 56);
this.groupBox1.Name = „groupBox1“;
this.groupBox1.Size = new System.Drawing.Size(120, 248);
this.groupBox1.TabIndex = 2;
this.groupBox1.TabStop = false;
this.groupBox1.Text = „groupBox1“;
//
// numericUpDown1
//
this.numericUpDown1.Location = new System.Drawing.Point(32, 208);
this.numericUpDown1.Name = „numericUpDown1“;
this.numericUpDown1.Size = new System.Drawing.Size(40, 20);
this.numericUpDown1.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(200, 413);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.panel1});
this.Name = „Form1“;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = „Form1“;
this.Resize += new System.EventHandler(this.Form1_Resize);
this.panel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
this.panel3.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
this.ResumeLayout(false);

}
#endregion

///
/// Der Haupteinstiegspunkt für die Anwendung.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void btnPanel2_Click(object sender, System.EventArgs e)
{
this.panel3.Location = new System.Drawing.Point(0, this.panel2.Height-this.btnPanel3.Height);
this.panel3.Height = this.panel1.Height;
}

private void btnPanel3_Click(object sender, System.EventArgs e)
{
this.panel3.Location = new System.Drawing.Point(0, this.btnPanel2.Height);
this.panel3.Height = this.panel1.Height;
}

private void Form1_Resize(object sender, System.EventArgs e)
{
panel3.Location=new Point(0, this.panel2.Height-this.btnPanel3.Height);
this.panel2.Height = this.Height;
this.panel3.Height = this.Height;
}
}
}
/*** Anfang ***/

Hi Andreas,

kannst Du nicht einfach das Property TOP prüfen ?

LG
Mario

Hallo Andreas,

was ist eigentlich das Problem?

  1. willst Du, dass btnPanel3 nur beim Klick auf btnPanel2 nach unten geht und nicht beim Form1.Resize?
    oder
  2. weißt Du nach Resize nicht, ob Dein btnPanel3 oben oder unten ist?

zu 1.: dann ändere die Location in dem Resize-EventHandler nicht.
zu 2.: merke Dir einfach in einer Variablen, ob der btnPanel3 oben oder unten ist.

Teilst Du uns auch irgendwann mit, was Du mit Deiner Programmierung bezwecken willst?

Gruß
Thomas

Moin, Moin.
Ich brauche ein bischen Hilfe.
Wenn Form1 startet, ist btnPanel2 oben und btnPanel3 unten.
So soll es auch sein. Und wenn ich auf den Button „Panel3“
klicke
geht dieser nach oben. Auch noch in Ordnung.
Erst wenn ich wieder auf Button „Panel2“ klicke soll Button
„Panel3“ nach unten springen.
Dies soll auch funktionieren, wenn ich Form1_Resize auslöse.
Wie kann ich erreichen, das btnPanel3 (bei einem
Click-Ereignis) weiß jetzt ist er oben und muß runter oder er
ist unten und muß nach oben??
Kann mir jemand helfen??

MfG
Andreas

Hallo Thomas,
erst einmal Danke für Deine Hilfe.
Ich habe mein „Problem“ alleine gelöst. ;o)
Ich wollte die Outlook-Leiste nachbilden.
Ein Button oben, zwei Button unten.
Durch jeweiliges Klicken der Buttons erhält man Zugriff
auf verschiedene Flächen/Panels.
Meine einfache Lösung liegt in den AnchorStyles und Location der
zu verwendeten Button.

Gruß
Andreas