I am coding a C# Form Application. The following code is my 'MainForm.cs'.
using CefSharp;
using CefSharp.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WinFormsChromium
{
public partial class MainForm : Form
{
public ChromiumWebBrowser browser;
public void InitBrowser()
{
Cef.Initialize(new CefSettings());
browser = new ChromiumWebBrowser("www.google.com");
this.Controls.Add(browser);
browser.Dock = DockStyle.Fill;
browser.LoadingStateChanged += browser_LoadingStateChanged;
}
private void browser_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e)
{
if (e.IsLoading == false)
{
browser.ExecuteScriptAsync("alert('All Resources Have Loaded');");
}
}
public MainForm()
{
InitializeComponent();
InitBrowser();
}
}
}
There is no problem with that file. I am having a problem with my 'MainForm.Designer.cs'. The following code is that file.
namespace Test
{
partial class MainForm
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.SuspendLayout();
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(534, 279);
this.Name = "MainForm";
this.Text = "Test";
this.ResumeLayout(false);
}
}
}
The error is "Test.MainForm.Dispose(bool): no suitable method to override (CS0115)". I think the problem is the 'protected override void Dispose(bool disposing)'. How can i fix it?
the problem is in different namespaces
You have namespace WinFormsChromium for the .cs file and Test in the Designer.cs file
Please replace namespace Test with namespace WinFormsChromium in the .Designer.cs file to make partial class MainForm parts visible to each other
Related
Hey I got Code Written in Class Form1 And Form2. I want to call the method openkindForm() from Form2. I tried every soloution I found. I got this one at the moment which is not working it gives me a System.NullReferenceException. I do not know why it isnt working. I tried it so long but whatever I do it will not workout somehow. I would be thankfull for an answer.
Kind regards
First Class
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FBDP00
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
submenupanel.Visible = false;
}
private void funktionenSM_Click(object sender, EventArgs e)
{
switch (submenupanel.Visible)
{
case true:
submenupanel.Visible = false;
break;
case false:
submenupanel.Visible = true;
break;
}
}
public void neuepruefungSm_Click(object sender, EventArgs e)
{
submenupanel.Visible = false;
openkindForm(new Form2());
}
public Form activeForm = null;
public void openkindForm(Form childForm)
{
if (activeForm != null)
{
activeForm.Close();
}
activeForm = childForm;
childForm.TopLevel = false;
childForm.FormBorderStyle = FormBorderStyle.None;
childForm.Dock = DockStyle.Fill;
backgroundPanel.Controls.Add(childForm);
childForm.Show();
}
}
}
Class 2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static FBDP00.Form1;
namespace FBDP00
{
public partial class Form2 : Form
{
public Form1 testform;
public Form2()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
}
private void funktionenSM_Click(object sender, EventArgs e)
{
}
public void baukontrolleb_Click(object sender, EventArgs e)
{
testform.openkindForm(new Form3());
}
}
}
In Form2 you have defined a variable for Form1 (testform), but you don't set this anywhere. So this is why you get a Null reference error when you try to use it, because it is null!
So when you create your Form2 then you need to set this value. In your case, maybe in the constructor like this.
public Form1 testform;
private Form2(Form1 f1)
{
InitializeComponent();
testform = f1;
}
Then call it like this:
public void neuepruefungSm_Click(object sender, EventArgs e)
{
submenupanel.Visible = false;
openkindForm(new Form2(this));
}
However, looking at your openkindForm method, it seems to me that this really has nothing to do with Form1, and shares no variables, so should not be in this class.
You should either make this static (together with the activeForm variable), or make it a Singleton class instead. But certainly this should be a separate class.
Is there any way to retrieve the updated size of panel after FormWindowState.Maximized? I can get the size of the panel but it's giving the original size of panel.
Thanks;
By the way this is the code for usercontrol
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication8
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
private void UserControl1_Load(object sender, EventArgs e)
{
//this is the way i retrieve the panel size
Form1 f = new Form1();
this.Size = f.Size;
}
}
}
this is forms code, the panel has 4 activated anchors
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
UserControl1 n = new UserControl1();
panel1.Controls.Add(n);
}
private void Form1_Load(object sender, EventArgs e)
{
WindowState = FormWindowState.Maximized;
}
}
}
If what you want to do is to resize the user control every time the parent Form is resized, you could use the Resize event of the ParentForm:
Main form:
using System;
using System.Drawing;
using System.Windows.Forms;
namespace ans
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
var uc = new UserControl2();
uc.Location = new Point(0, 0);
this.Controls.Add(uc);
WindowState = FormWindowState.Maximized;
}
}
}
User control:
using System;
using System.Drawing;
using System.Windows.Forms;
namespace ans
{
public partial class UserControl2 : UserControl
{
public UserControl2()
{
InitializeComponent();
}
private void UserControl2_Load(object sender, EventArgs e)
{
this.BackColor = Color.Aqua;
if (this.ParentForm != null)
{
this.Size = this.ParentForm.Size;
this.ParentForm.Resize += ParentForm_Resize;
}
}
private void ParentForm_Resize(object sender, EventArgs e)
{
this.Size = ((Form)sender).Size;
}
}
}
If you want the UserControl you create dynamically at runtime to grow and shrink with the control that it is placed on, then set the Dock property of the UserControl to Fill at runtime:
private void button1_Click(object sender, EventArgs e)
{
MyUserControl userControl = new MyUserControl();
panel1.Controls.Add(userControl);
userControl.Dock = DockStyle.Fill;
}
I'm developing a windows form that opens a web application page.
I'm obliged to use the COM AxWebBrowser for this goal.
the problem is when a window.Open() action is executed in the web page, the new page is opened in my axWebBrowser and another blank page is shown .I need to force the new window to open in the blank page without affecting the main page.
I tried the code below but it doesn't work fine:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MyProject.MyNamespace
{
public partial class PopupWindow : Form
{
#region Fields
private PopupWindow _popupWindow;
#endregion
#region Ctr
public PopupWindow()
{
this.InitializeComponent();
this.axWebBrowser.Silent = true;
this.axWebBrowser.NewWindow3 += new AxSHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(axWebBrowser_NewWindow3);
this.FormClosing += PopupWindow_FormClosing;
this.Shown += new EventHandler(PopupWindow_Shown);
}
private void axWebBrowser_NewWindow3(object sender, AxSHDocVw.DWebBrowserEvents2_NewWindow3Event e)
{
this._popupWindow = null;
this._popupWindow = new PopupWindow();
this._popupWindow.WindowState = FormWindowState.Maximized;
this._popupWindow.AXWebBrowser.RegisterAsBrowser = true;
e.ppDisp = this._popupWindow.AXWebBrowser.Application;
this._popupWindow.Visible = true;
}
#endregion
#region Properties
public AxSHDocVw.AxWebBrowser AXWebBrowser
{
get { return this.axWebBrowser; }
}
#endregion
#region Methods
private void PopupWindow_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
this.Hide();
}
private void PopupWindow_Shown(object sender, EventArgs e)
{
this.Size = new Size(this.Width + 2, this.Height + 2);
}
#endregion
}
}
Thank you for your help!
I'm creating a Windows Runtime App and it seems I don't have any access to the MessageBox class. The documentation states it's in the System.Windows namespace, so I added it and I still don't have access to the MessageBox class.
using System.Windows;
public sealed partial class BillPage : Page
{
private Edge myEdge;
public BillPage()
{
this.InitializeComponent();
MessageBox.Show("Test", "Test");
}
}
Any idea what's up? Am I just an idiot or what?
Documentation: http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.messagebox(v=vs.105).aspx
Full Code:
using EdgeApp.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Graphics.Display;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Windows;
// The Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkID=390556
namespace EdgeApp
{
public sealed partial class BillPage : Page
{
private NavigationHelper navigationHelper;
private ObservableDictionary defaultViewModel = new ObservableDictionary();
private Edge myEdge;
public BillPage()
{
this.InitializeComponent();
myEdge = new Edge();
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += this.NavigationHelper_LoadState;
this.navigationHelper.SaveState += this.NavigationHelper_SaveState;
}
public NavigationHelper NavigationHelper
{
get { return this.navigationHelper; }
}
public ObservableDictionary DefaultViewModel
{
get { return this.defaultViewModel; }
}
private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
}
private void NavigationHelper_SaveState(object sender, SaveStateEventArgs e)
{
}
#region NavigationHelper registration
protected override void OnNavigatedTo(NavigationEventArgs e)
{
this.navigationHelper.OnNavigatedTo(e);
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
this.navigationHelper.OnNavigatedFrom(e);
}
#endregion
private void MessageBoxTest(object sender, RoutedEventArgs e)
{
MessageBox.Show("text");
}
}
}
In Windows Runtime App, MessageBox can be shown by this code:
new MessageDialog("Your Message Content").ShowAsync();
I have a project with some classes. I wanted to change one's(classA) design so I created a new project in expression blend 4. I want to use this in order to do this I need to access that project from main project.
I have in that class:
class1 c = new class1();
c.pass = read.Value;
if (c.ShowDialog() == DialogResult.OK)
{
read.Close();
return c.status;
}
I tried this https://stackoverflow.com/a/3556586/2763129 but it doesn't work. Is it even possible?
ClassA
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace momo
{
public partial class ClassA : Form
{
public string pass;
public bool status;
public ClassA()
{
status = false;
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.Equals(pass))
{
status = true;
this.Close();
}
else
{
MessageBox.Show("Errör", MessageBoxButtons.OK, MessageBoxIcon.Error);
status = false;
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
my wpf which I try to ipmlement
using System;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Windows;
using System.Windows.Controls;
//using System.Windows.Forms;
namespace ZGNH
{
public class ayat
{
//public checkpassword()
//{
// status = false;
// this.InitializeComponent();
//}
public string pass;
public bool status;
}
public partial class MainWindow : Window
{
ayat saf = new ayat();
string pass;
bool status;
//public string pass;
//public bool status;
public MainWindow()
{
//InitializeCo
this.InitializeComponent();
// saf.pass = pass;
//saf.status = status;
// Insert code required on object creation below this point.
}
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
this.Close();
//
}
private void Button1_Click(object sender, System.Windows.RoutedEventArgs e)
{
//pass="c";
//password
if (pboxxx.Password.Equals(pass))
{
status = true;
//PasswordBox s =new PasswordBox();
this.Close();
}
else
{
Window1 s = new Window1();
s.ShowDialog();
//MessageBox.Show("Errör", MessageBoxButtons.OK, MessageBoxIcon.Error);
status = false;
}
}
}
}
edit : I tried adding this to mainwindow.xaml.cs
public void show()
{
Window.Show();
}
but it gives The type or namespace name 'MainWindow' could not be found (are you missing a using directive or an assembly reference?) .Visual Studio 2012\Projects\momolocker\momo\memoform.cs 14 7 Momo