Icon i visual studio og winforms.
Nu har jeg batteled lang tid med at få vist mit ikon i mit program. Min oprindelige idet var at skifte mellem forskellige ikoner for at vise om der var forbindelse til en webservice. det virker ikke.Hvis jeg læser direkte fra .ico filen fra disken, viser den bare et standard ikon jeg ikke selv har lavet. Jeg har åbnet mit ikon i paint og der er det fint nok.
Hvis jeg kompilerer den som embedded resource og prøver at hente den fra min klasses resourcer fejler programmet.
her er min kode:
______________________
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace teststatus
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private teststatus.UserControl1 userControl11;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.userControl11 = new teststatus.UserControl1();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(152, 72);
this.button1.Name = "button1";
this.button1.TabIndex = 2;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// userControl11
//
this.userControl11.BackColor = System.Drawing.Color.Red;
this.userControl11.Dock = System.Windows.Forms.DockStyle.Bottom;
this.userControl11.Location = new System.Drawing.Point(0, 238);
this.userControl11.Name = "userControl11";
this.userControl11.Size = new System.Drawing.Size(400, 32);
this.userControl11.TabIndex = 3;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(400, 270);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.userControl11,
this.button1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
this.userControl11.setTime();
}
}
}
__________________
og usercontrol:
____________________
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace teststatus
{
/// <summary>
/// Summary description for UserControl1.
/// </summary>
public class UserControl1 : System.Windows.Forms.UserControl
{
private System.Windows.Forms.StatusBar statusBar1;
public System.Windows.Forms.StatusBarPanel statusBarPanel1;
private System.Windows.Forms.StatusBarPanel statusBarPanel2;
private System.Windows.Forms.StatusBarPanel statusBarPanel3;
private System.Windows.Forms.StatusBarPanel statusBarPanel4;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public UserControl1()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitForm call
}
public void setTime()
{
DateTime dt = DateTime.Now;
this.statusBarPanel3.Text = dt.ToShortDateString();
this.statusBarPanel4.Text = dt.ToLongTimeString();
//Icon test = new Icon(@"c:\iForbindelseTesting.ico");
//this.statusBarPanel1.Icon = test;
//ELLER
//this.statusBarPanel1.Icon = new Icon(typeof(Form1),"Form1.Icon1.ico");
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(UserControl1));
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanel2 = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanel3 = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanel4 = new System.Windows.Forms.StatusBarPanel();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel3)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel4)).BeginInit();
this.SuspendLayout();
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 80);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.statusBarPanel1,
this.statusBarPanel2,
this.statusBarPanel3,
this.statusBarPanel4});
this.statusBar1.ShowPanels = true;
this.statusBar1.Size = new System.Drawing.Size(392, 24);
this.statusBar1.TabIndex = 0;
this.statusBar1.Text = "statusBar1";
//
// statusBarPanel1
//
this.statusBarPanel1.BorderStyle = System.Windows.Forms.StatusBarPanelBorderStyle.Raised;
this.statusBarPanel1.Icon = ((System.Drawing.Icon)(resources.GetObject("statusBarPanel1.Icon")));
this.statusBarPanel1.Width = 50;
//
// statusBarPanel2
//
this.statusBarPanel2.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
this.statusBarPanel2.BorderStyle = System.Windows.Forms.StatusBarPanelBorderStyle.None;
this.statusBarPanel2.Text = "Tilstand";
this.statusBarPanel2.ToolTipText = "Om der er forbindelse til server eller ej";
this.statusBarPanel2.Width = 215;
//
// statusBarPanel3
//
this.statusBarPanel3.Alignment = System.Windows.Forms.HorizontalAlignment.Right;
this.statusBarPanel3.Text = "dato";
this.statusBarPanel3.ToolTipText = "Dagens dato";
this.statusBarPanel3.Width = 63;
//
// statusBarPanel4
//
this.statusBarPanel4.Alignment = System.Windows.Forms.HorizontalAlignment.Right;
this.statusBarPanel4.Text = "tid";
this.statusBarPanel4.ToolTipText = "Sidst der var forbindelse til server";
this.statusBarPanel4.Width = 48;
//
// UserControl1
//
this.BackColor = System.Drawing.Color.Red;
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.statusBar1});
this.Name = "UserControl1";
this.Size = new System.Drawing.Size(392, 104);
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel3)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel4)).EndInit();
this.ResumeLayout(false);
}
#endregion
}
}
______________
