Can anyone have a look at my code, I don't quite follow what is the error about
private void InitializeComponent()
{
this.WebBrowserHost = new System.Windows.Forms.Integration.ElementHost();
this.SuspendLayout();
//
// WebBrowserHost
//
this.WebBrowserHost.Dock = System.Windows.Forms.DockStyle.Fill;
this.WebBrowserHost.Location = new System.Drawing.Point(0, 0);
this.WebBrowserHost.MinimumSize = new System.Drawing.Size(20, 20);
this.WebBrowserHost.Name = "WebBrowserHost";
this.WebBrowserHost.Size = new System.Drawing.Size(284, 262);
this.WebBrowserHost.TabIndex = 0;
//
// AuthorizationWindow
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.WebBrowserHost);
this.Name = "AuthorizationWindow";
this.Text = "AuthorizationWindow";
this.ResumeLayout(false);
}
In my form I just have a WebBrowser control and I am having the error:
Cannot implicitly convert type
'System.Windows.Forms.Integration.ElementHost' to
'System.Windows.Forms.WebBrowser'
After Initialize I need ElementHost.Child like this
public AuthorizationWindow()
{
// This call is required by the designer.
InitializeComponent();
WebBrowser = new System.Windows.Controls.WebBrowser();
WebBrowserHost.Child = WebBrowser;
WebBrowser.Navigating += WebBrowser_Navigating;
WebBrowser.LoadCompleted += WebBrowser_LoadCompleted;
_authorization = new AuthorizationState();
}
Did you try changing the line
this.WebBrowserHost = new System.Windows.Forms.Integration.ElementHost();
to
this.WebBrowserHost = new System.Windows.Forms.WebBrowser();
?
I am unable to add webbrowser control to panel in winapp,getting this error"Unable to get the window handle for the 'WebBrowser' control. Windowless ActiveX controls are not supported."i also tried to do it using STAthread like
Thread uy = new Thread(me_p);
uy.SetApartmentState(ApartmentState.STA);
uy.Start();
private void me_p(object obj)
{
//throw new NotImplementedException();
this.p_bottom.Controls.Add(this.webBrowser2);
}
It works fine when done this way
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.webBrowser1 = new System.Windows.Forms.WebBrowser();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.Controls.Add(this.webBrowser1);
this.panel1.Location = new System.Drawing.Point(47, 149);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(200, 100);
this.panel1.TabIndex = 0;
//
// webBrowser1
//
this.webBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
this.webBrowser1.Location = new System.Drawing.Point(0, 0);
this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
this.webBrowser1.Name = "webBrowser1";
this.webBrowser1.Size = new System.Drawing.Size(200, 100);
this.webBrowser1.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 261);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Text = "Form1";
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.WebBrowser webBrowser1;
You can have a browser pre initialized and later use it in your threads.
I decided to change a listBox1 item in my form1 designer to public static instead of private to access it on another form. And once I had done that It had errored and not allowed me to changed things on the form itself and just tells me this error at the top
The variable 'listBox1' is either undeclared or was never assigned.
The error is shown on the following line
this.panel1.Controls.Add(listBox1);
My Designer for my form below:
namespace Mercury.Forms
{
partial class Inside
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (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.pictureBox1 = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.panel1 = new System.Windows.Forms.Panel();
Inside.listBox1 = new System.Windows.Forms.ListBox();
this.label3 = new System.Windows.Forms.Label();
this.panel2 = new System.Windows.Forms.Panel();
this.button1 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.Color.White;
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox1.Image = global::Mercury.Properties.Resources.pooltablegodass_500x750;
this.pictureBox1.Location = new System.Drawing.Point(12, 11);
this.pictureBox1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(54, 48);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.ForeColor = System.Drawing.SystemColors.ButtonHighlight;
this.label1.Location = new System.Drawing.Point(74, 15);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(82, 20);
this.label1.TabIndex = 1;
this.label1.Text = "Ash Smith";
this.label1.Click += new System.EventHandler(this.label1_Click);
//
// label2
//
this.label2.AutoSize = true;
this.label2.ForeColor = System.Drawing.SystemColors.ButtonHighlight;
this.label2.Location = new System.Drawing.Point(76, 37);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(66, 13);
this.label2.TabIndex = 2;
this.label2.Text = "ashleytechie";
this.label2.Click += new System.EventHandler(this.label2_Click);
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.panel1.Controls.Add(this.button1);
this.panel1.Controls.Add(this.label3);
this.panel1.Controls.Add(listBox1);
this.panel1.Controls.Add(this.label2);
this.panel1.Controls.Add(this.label1);
this.panel1.Controls.Add(this.pictureBox1);
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(200, 348);
this.panel1.TabIndex = 3;
//
// listBox1
//
listBox1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
listBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
listBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
listBox1.ForeColor = System.Drawing.SystemColors.Window;
listBox1.FormattingEnabled = true;
listBox1.ItemHeight = 15;
listBox1.Items.AddRange(new object[] {
"Jake Simpson",
"Adam Jones",
"Jane Peters",
"Ashley Smith",
"Sam Smith",
"Joe Phelan",
"Peter Black",
"Tracy Bratford",
"Jamie Harrison",
"Peter Slims"});
listBox1.Location = new System.Drawing.Point(16, 107);
listBox1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
listBox1.Name = "listBox1";
listBox1.Size = new System.Drawing.Size(144, 180);
listBox1.TabIndex = 3;
listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label3.ForeColor = System.Drawing.SystemColors.Window;
this.label3.Location = new System.Drawing.Point(12, 79);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(105, 24);
this.label3.TabIndex = 4;
this.label3.Text = "Contact List";
//
// panel2
//
this.panel2.Location = new System.Drawing.Point(205, 7);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(518, 335);
this.panel2.TabIndex = 4;
//
// button1
//
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button1.ForeColor = System.Drawing.SystemColors.ButtonHighlight;
this.button1.Location = new System.Drawing.Point(16, 304);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(170, 31);
this.button1.TabIndex = 5;
this.button1.Text = "Edit Profile";
this.button1.UseVisualStyleBackColor = true;
//
// Inside
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.ButtonHighlight;
this.ClientSize = new System.Drawing.Size(730, 347);
this.Controls.Add(this.panel2);
this.Controls.Add(this.panel1);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "Inside";
this.Text = "Inside";
this.Load += new System.EventHandler(this.Inside_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Panel panel1;
public static System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Button button1;
}
}
Change this back to what it was previously: (public to private, remove static)
public static System.Windows.Forms.ListBox listBox1;
Add this in the code-behind in your Form: (you don't need a setter since you won't be creating a new ListBox from the other Forms... I hope)
public ListBox MyListBox
{
get { return listBox1; }
}
Now in other Forms (assuming they're being created by some process in your first Form), you'll pass a reference to the current instance of your Form with the ListBox on it, so you can actually access the public property you just created:
public class SecondForm : Form
{
public SecondForm(FirstForm firstForm)
{
// do something with firstForm.MyListBox
}
}
Lastly, I'd say be careful how much you do this. Forms being able to access each other's controls seems messy to me. If you added more details about exactly what you're trying to accomplish with this, we might be able to provide a better alternative.
Your issue is that you changed the code in the designer file so that listBox1 is now static. You can't do this because the designer must be able to instantiate an instance of ListBox.
What it sounds like you are trying to do is you are trying to modify the listbox from another form. The proper way you should do this is through properties. In your code (not the designer code, but the code behind code), have something like this:
public ListBox MyListBox
{
get
{
return listBox1;
}
}
You shouldn't change anything in the .Designer.cs file. If you want to change access modifiers you should do so through the Properties window.
That being said, your public change was fine, you just can't make it static. For the designer to function all the controls in the form must be independent to each instantiation.
// what the code will look like when you change it from the Properties window
public System.Windows.Forms.ListBox listBox1;
If you were to make the ListBox static, you would access it like
ListBox listbox = Inside.listBox1;
which doesn't make much sense if you have more than one Inside form floating around. If you make it non-static you can still access it from wherever you want as long as you have an instance of the Inside class.
Inside inside = new Inside();
ListBox listbox = inside.listBox1;
I have this simple code:
private void buttonOpen_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox2.Text = openFileDialog1.FileName;
}
}
When I run program form doesn't show and exit of debugging mode.
In output view writes:The program '[4244] openfiledialog.vshost.exe: Managed (v4.0.30319)' has exited with code 1073741855 (0x4000001f).
I have Visual Studio 2010 Professional.
Edit:form1.designer.cs
private void InitializeComponent()
{
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.buttonOpen = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// openFileDialog1
//
this.openFileDialog1.FileName = "openFileDialog1";
//
// buttonOpen
//
this.buttonOpen.Location = new System.Drawing.Point(13, 48);
this.buttonOpen.Name = "buttonOpen";
this.buttonOpen.Size = new System.Drawing.Size(75, 23);
this.buttonOpen.TabIndex = 0;
this.buttonOpen.Text = "open";
this.buttonOpen.UseVisualStyleBackColor = true;
this.buttonOpen.Click += new System.EventHandler(this.buttonOpen_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(113, 50);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(279, 20);
this.textBox1.TabIndex = 1;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(13, 98);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(385, 20);
this.textBox2.TabIndex = 2;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(445, 216);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.buttonOpen);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
As a general rule I initialize and use my OpenFileDialog's within the event that is calling it. I can't think of a circumstance in which I would want it to be a property of my window. The first thing I would do is delete it as a property and initialize it in your event.
private void buttonOpen_Click(object sender, EventArgs e)
{
using (OpenFileDialog openFileDialog1 = new OpenFileDialog())
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox2.Text = openFileDialog1.FileName;
}
}
}
You don't need to set the FileName property to anything because the dialog will do it for you.
The only thing I found on your error code was this (Program and debugger quit without indication of problem). Which in your current code I cannot find anything that would cause this. If you are accessing unmanaged code you may need to enable unmanaged code debugging.
I am going to let users create Forms during RunTime and add them to a project. I have done the designing and the UI of the form with the help of an open source Form Designer.
Here is the image of the Form Designer:
Lets assume I have the Form1.cs and Form1.cs[Designer] files which are enough for a WinForm. But how do I compile it to a DLL or an EXE and add it to the project? Any ideas? Any clues?
Thanks!!
EDIT
It creates this code.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.CheckBox checkBox1;
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(71, 49);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseCompatibleTextRendering = true;
this.button1.UseVisualStyleBackColor = true;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(71, 94);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 1;
//
// checkBox1
//
this.checkBox1.Location = new System.Drawing.Point(38, 184);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(104, 24);
this.checkBox1.TabIndex = 2;
this.checkBox1.Text = "checkBox1";
this.checkBox1.UseCompatibleTextRendering = true;
this.checkBox1.UseVisualStyleBackColor = true;
//
// form1
//
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Name = "form1";
this.ResumeLayout(false);
this.PerformLayout();
}
}
I will do some extra coding to the rest of the code myself. but I dont know how to compile it and add it to the main exe?
The clue is System.CodeDom.Compiler
i think Form1.cs will contain no code (other then InitializeComponents call in constructor). so if you merge it with the designer code with simple string operations your job will be easier.