19. december 2004 - 13:49Der er
18 kommentarer og 1 løsning
Aktion på knapper og menuer
Hvordan kobler jeg tingene sammen i #developer? Hvordan skal tingene ligge? I hver sin .cs fil eller hvordan. Jeg kan ikke få den til at sætte events på knapper og menuer.
Sandsynligvis har jeg ikke fattet en skid af det hele.
Min kode:
/* * Created by SharpDevelop. * User: Jeppe * Date: 18-12-2004 * Time: 14:12 * * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; using System.Drawing; using System.Windows.Forms;
namespace tets { /// <summary> /// Description of MainForm. /// </summary> public class MainForm : System.Windows.Forms.Form { private System.Windows.Forms.MenuItem menuItem6; private System.Windows.Forms.MenuItem Opret; private System.Windows.Forms.Button button1; private System.Data.Odbc.OdbcConnection odbcConnection1; private System.Windows.Forms.MenuItem menuItem4; private System.Windows.Forms.MenuItem menuItem3; private System.Windows.Forms.MenuItem menuItem2; private System.Windows.Forms.MenuItem menuItem1; private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.MenuItem menuItem5; public MainForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent();
// // TODO: Add constructor code after the InitializeComponent() call. // }
[STAThread] public static void Main(string[] args) { Application.Run(new MainForm()); }
#region Windows Forms Designer generated code /// <summary> /// This method is required for Windows Forms designer support. /// Do not change the method contents inside the source code editor. The Forms designer might /// not be able to load this method if it was changed manually. /// </summary> private void InitializeComponent() { System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MainForm)); this.menuItem5 = new System.Windows.Forms.MenuItem(); this.mainMenu1 = new System.Windows.Forms.MainMenu(); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.menuItem2 = new System.Windows.Forms.MenuItem(); this.menuItem3 = new System.Windows.Forms.MenuItem(); this.menuItem4 = new System.Windows.Forms.MenuItem(); this.odbcConnection1 = new System.Data.Odbc.OdbcConnection(); this.button1 = new System.Windows.Forms.Button(); this.Opret = new System.Windows.Forms.MenuItem(); this.menuItem6 = new System.Windows.Forms.MenuItem(); this.SuspendLayout(); // // menuItem5 // this.menuItem5.Index = -1; this.menuItem5.Text = ""; // // mainMenu1 // this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem6}); // // menuItem1 // this.menuItem1.Index = -1; this.menuItem1.Text = ""; // // menuItem2 // this.menuItem2.Index = -1; this.menuItem2.Text = ""; // // menuItem3 // this.menuItem3.Index = -1; this.menuItem3.Text = ""; // // menuItem4 // this.menuItem4.Index = -1; this.menuItem4.Text = ""; // // button1 // this.button1.BackColor = System.Drawing.Color.White; this.button1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("button1.BackgroundImage"))); this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.button1.Location = new System.Drawing.Point(344, 280); this.button1.Name = "button1"; this.button1.TabIndex = 1; this.button1.Click += new System.EventHandler(this.Button1Click); // // Opret // this.Opret.Index = -1; this.Opret.Text = ""; // // menuItem6 // this.menuItem6.Index = 0; this.menuItem6.Text = ""; // // MainForm // this.AutoScaleBaseSize = new System.Drawing.Size(5, 14); this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage"))); this.ClientSize = new System.Drawing.Size(480, 342); this.Controls.Add(this.button1); this.ForeColor = System.Drawing.SystemColors.Window; this.Menu = this.mainMenu1; this.Name = "MainForm"; this.Text = "MainForm"; this.ResumeLayout(false); } #endregion void Button1Click(object sender, System.EventArgs e) { Form f = new Form1(); f.Show(); }
} public Form1() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent();
// // TODO: Add constructor code after the InitializeComponent() call. // } }
Eller måske en ville være rar at smide et eksempel der skifter mellem en knap 1 og en knap 2
Ja, det hjalp jo unægteligt. Så skal jeg bare lige sætte en masse ting ind. Men den åbner et nyt vindue. Kan man ikke få den til at åbne i samme vindue?
ja ja undskyld :-) Jeg bad om en ny side, men i samme vindue forståes. Men jeg har fundet en spændende tutorial der kører i console i stedet for i vinduer. Den prøver jeg lige at se, om ikke jeg kan blive lidt klog af. Så må det pæne udseende komme senere.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.