Should a UserControl's Refresh() method be automatically called when its container's Refresh() method is called? - user-controls

In a project created in Windows 7 and Visual Studio 2012, I have a form with the following code:
public partial class Form1 : Form
{
private Form2 m_form2;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
m_form2 = new Form2();
m_form2.Show();
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("Refreshing form1");
Refresh();
m_form2.Refresh();
}
}
Form2 has the following method:
public override void Refresh()
{
MessageBox.Show("Refreshing Form2");
base.Refresh();
}
Form2 contains an instance of the RefreshTestControl, which contains this method:
public override void Refresh()
{
MessageBox.Show("Control is being refreshed.");
base.Refresh();
}
I expected that my control's overridden Refresh() method would get called automatically when Form2.Refresh() is called, but it's not. Why not? Am I doing something wrong, or do I just not understand what happens when a form is refreshed?

Related

Excel AddIn Event: How to display a dialog asking the user whether the workbook should be saved?

Before the user is allowed to save an Excel workbook that is "invalid", I would like to inform them that they have managed to damage it and give them the opportunity to abandon all modifications.
By pressing a few times the [TAB] key, I was able to generate most of the code below:
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
namespace WithBeforeSave
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.WorkbookBeforeSave += new Excel.AppEvents_WorkbookBeforeSaveEventHandler(Application_WorkbookBeforeSave);
}
void Application_WorkbookBeforeSave(Excel.Workbook Wb, bool SaveAsUI, ref bool Cancel)
{
MessageBox.Show("How do I put the proper dialog here?");
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
}
}
Therefore, all I need is the C# equivalent to this:
This example prompts the user for a yes or no response before saving the workbook.
TIA
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
namespace WithBeforeSave
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.WorkbookBeforeSave += new Excel.AppEvents_WorkbookBeforeSaveEventHandler(Application_WorkbookBeforeSave);
}
void Application_WorkbookBeforeSave(Excel.Workbook Wb, bool SaveAsUI, ref bool Cancel)
{
if (DialogResult.No == MessageBox.Show("Are you sure you want to save the DEFECTIVE, INVALID workbook?", "Example", MessageBoxButtons.YesNo))
{
Cancel = true;
MessageBox.Show("Save is canceled.");
}
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
}
}
That's it. I found the answer here:
This example prompts the user for a yes or no response before saving any workbook.

How to override a method and pass parameters in C#?

I have a public method in project and here is that method.
public bool SaveDocument(string customer)
{
//some codes
}
I have another project in same solution with this method
private void buttonSaveReport_Click(object sender, EventArgs e)
{
}
button click event I need to pass 3 parameters (name,title,isbn) to SaveDocument() method and override it.I am having a difficulty with implementing this.Trying with this and can anyone help me out to complete it.
public class Ext : DocumentManager.DocumentManager
{
public override void SaveDocument()
{
base.SaveDocumentCustomer(customer);
}
}
Thanks

Cannot properly set visible component

I'm trying to implement Menu with select box which sets to display or not component. I have this checkbox:
final CheckMenuItem toolbarSubMenuNavigation = new CheckMenuItem("Navigation");
toolbarSubMenuNavigation.setOnAction(new EventHandler<ActionEvent>()
{
#Override
public void handle(ActionEvent e)
{
DataTabs.renderTab = toolbarSubMenuNavigation.isSelected();
// call here the getter setter and send boolean flag
System.out.println("subsystem1 #1 Enabled!");
}
});
And I have this tabpane which I want to render only if I have selected the checkbox:
public static boolean renderTab;
public DataTabs()
{
}
public boolean isRenderTab()
{
return renderTab;
}
public void setRenderTab(boolean renderTab)
{
this.renderTab = renderTab;
}
// below this code
tabPane.setVisible(renderTab);
When I run the code it's not working. I also tested this:
DataTabs tabs = new DataTabs(); // instantiate first
tabs.setRenderTab(toolbarSubMenuNavigation.isSelected());
public static boolean renderTab;
TabPane tabPane = new TabPane();
public DataTabs()
{
}
public boolean isRenderTab()
{
return renderTab;
}
public void setRenderTab(boolean renderTab)
{
tabPane.setVisible(renderTab);
}
But again there is no result when I run the code and I check or uncheck the checkbox.
This is the complete source code:
http://pastebin.com/tkj4Fby1
Maybe I need to add listener or something else which I'm missing?
EDIT
Test 3
I also tested this code:
final CheckMenuItem toolbarSubMenuNavigation = new CheckMenuItem("Navigation");
toolbarSubMenuNavigation.setOnAction(new EventHandler<ActionEvent>()
{
#Override
public void handle(ActionEvent e)
{
DataTabs.toolbarSubMenuNavigation = toolbarSubMenuNavigation;
// call here the getter setter and send boolean flag
System.out.println("subsystem1 #1 Enabled!");
}
});
// class with tabs
public static CheckMenuItem toolbarSubMenuNavigation;
public static CheckMenuItem getToolbarSubMenuNavigation()
{
return toolbarSubMenuNavigation;
}
public static void setToolbarSubMenuNavigation(CheckMenuItem toolbarSubMenuNavigation)
{
DataTabs.toolbarSubMenuNavigation = toolbarSubMenuNavigation;
}
// below
abPane.visibleProperty().bind(toolbarSubMenuNavigation.selectedProperty());
I get NPE when I run the code.
You can easely tell to your tab to be visible when you check the box in one line
yourTab.visibleProperty().bind(yourCheckBox.selectedProperty());
And just with this line your tabpane will be visible only when it's checked

web user control can create a default event?

[DefaultEvent("MyCustomEvent")]
public partial class WebUserControl1 : System.Web.UI.UserControl
{
public delegate void onButtonClick(object sender, Myeventargs e);
public event onButtonClick btnHandler;
protected void ASPxButton1_Click(object sender, EventArgs e)
{
if (btnHandler != null)
{
btnHandler(this,e);
}
}
}
this code can work with
public partial class jscript : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
XFButton1.MYClick += new EventHandler(XFButton1_MYClick);
}
void XFButton1_MYClick(object sender, EventArgs e)
{
ASPxLabel1.Text = "Hello";
}
but the problem is i want it automatically generate a new event when i double click on the button. can i done this by using a web user control ?
too bad to tell you that web user control may not able to do like that... pls read this http://dotnet-framework-aspnet.itgroups.info/32/9/thread-796040.html.

Execute public String

I have a public class EmailHelp.
In this class there is a public String called doIt.
How do i execute this public String DoIt from within let´s say a onClick event?
public class EmailHelp{
-----
public String DoIt {
------
public void crxExecute () {
execute DoIt
finish();
Thank you in advance.
Assuming that "DoIt" is not a static method, you'd need to create an instance of the EmailHelp class, and call that method:
public void Button_OnClick(object sender, EventArgs e)
{
var emailHelper = new EmailHelp();
emailHelper.DoIt();
}
The fact that it's not obvious that you need to instantiate EmailHelper may indicate that the method should in fact be a static one. If it were a static method, calling it would look like this:
public void Button_OnClick(object sender, EventArgs e)
{
EmailHelp.DoIt();
}

Resources