How to execute batch file from visual c# application - visual-c#-express-2010

This might be a very specific question, but how do I execute a batch file in a sub folder above the c# application; I am trying to reference the batch file using a button:
private void testButton_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("test.bat");
}

Try
private void testButton_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(#"..\test.bat");
}

Related

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

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?

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

C# read the text of dynamically created text box from other methode

If I created a textbox dynamically like this:
private void Form1_Load(object sender, EventArgs e)
{
TextBox tb=new TextBox();
...
this.Controls.Add(tb);
}
and if I have a button on my form and I want to read the text of the textbox from within the button click event handler
private void button1_Click(object sender, EventArgs e)
{
if(**tb.text**=="something") do something;
}
The problem is that I can't find the textbox control in the button handler.
Thank you in advance
you have to declare texbox out of the method,it has to be global. then you can reach textbox object
TextBox tb;
private void Form1_Load(object sender, EventArgs e)
{
tb=new TextBox();
...
this.Controls.Add(tb);
}
Declare TextBox as your Form class private member.
You could iterate through the Controls collection of an enumerable object like a TabControl, assuming this is a Windows form. Here's some from a project I'm working on, adapted for TextBox:
foreach (TabPage t in tcTabs.TabPages)
{
foreach (Control c in t.Controls)
{
MessageBox.Show(c.Name); // Just shows the control's name.
if (c is TextBox) // Is this a textbox?
{
if (c.Name == "txtOne") // Does it have a particular name?
{
TextBox tb = (TextBox) c; // Cast the Control as a TextBox
tb.Text = "test"; // Then you can access the TextBox control's properties
}
}
}
}
private TextBox tb = new TextBox();
private void Form1_Load(object sender, EventArgs e)
{
this.Controls.Add(tb);
}

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.

Resources