Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
am calling the function of a form from another form. It executes but do not really show up. so any suggestions??
My code goes like
In Form FrmA
private void Print()
{
FrmMenu ObjMain = new FrmMenu();
ObjMain.Show();
}
public void CreateButtons(string Action)
{
btn.Text=Action;
}
And When the Form FrmMenu gets open then another function gets executed in constructor of FrmMenu
Public FrmMenu()
{
FrmA f2 = new FrmA();
f2.CreateButtons("NEW");
}
But nothing happens ...!!! The function CreateButtons executes but do not show any changes
The text of button remain the same.
so please help me out.
EDITED
You must pass the instance of FrmA into the constructor of FrmMenu.
In FrmA:
private void Print()
{
FrmMenu ObjMain = new FrmMenu(this);
ObjMain.Show();
}
In FrmMenu:
public FrmMenu(FrmA f2)
{
f2.CreateButtons("NEW");
}
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 12 months ago.
Improve this question
I have this code:
<div class="col-lg-12 control-section toast-default-section">
<SfToast ID="toast_default" #ref="ToastObj" Title="Error" Content="#a" </SfToast>
</div>
#code{
a = "Test";
StringBuilder b = new StringBuilder();
b.Append("Hello ");
if (b.ToString() != "")
{
a = a+ b;
StateHasChanged();
await ToastObj.ShowAsync();
}
}
When this "ToastObj" open, I need click 2 times to refresh. I don't know why.
For example:
First Result: Test
Second Result: Test Hello
I need click two times to refresh.
For the future, it would be helpful to see all the code, including the SFToast component.
However, You are calling it correctly. All you have to do to Get the page to refresh is to have the code hit the "StateHasChanged()" function. I think the problem is that you have code sitting outside of any function. Consider the #code{} to act like a normal class file with a few diffrences. For example there is no "Constructor" but the first method called on creation will be the OnInitalized(). I suggest wrapping the code and making sure all variables are initialized
#code{
protected override void OnInitialized()
{
var a = "Test";
StringBuilder b = new StringBuilder();
b.Append("Hello ");
if (b.ToString() != "")
{
a = a+ b;
StateHasChanged();
await ToastObj.ShowAsync();
}
}
}
Try use InvokeAsync(StateHasChanged);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
private void button4_Click(object sender, EventArgs e)
{
Program.keepRunnig = true;
this.Close();
Thread.Sleep(1000);
StreamWriter stw = new StreamWriter(#"E:\NabilDataBase\ChangeFormLang\ChangeFormLang\1.txt");
switch (Thread.CurrentThread.CurrentUICulture.IetfLanguageTag)
{
case "en-US": Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ar-IQ");
// stw.Write("ar-IQ");
stw.Close();
break;
case "ar-AR": Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
// stw.Write("en-US");
stw.Close();
break;
}
this.Controls.Clear();
InitializeComponent();
}
I made a program multi language interface with thread class and added two language,my question is when I change the interface to another language that I added and close the form then I reopen it I see the interface returned to the default language, how can I save it the interface when closed.[enter image description here][1]
If you create a new Setting "Culture" you can save information at runtime like so:
Properties.Settings.Default.Culture= "ar-ar";
Properties.Settings.Default.Save();
And load it like so:
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Properties.Settings.Default.Culture);
How To: Write User Settings at Run Time with C#
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is this a write way?suggest me.
public Init_Circle Init_Circle(Point pt,double rad)
{
Point center=pt;
if (rbCircle.Checked==true)
{
pt.x = double.Parse(txtCirCntPtX.Text.Trim());
pt.y = double.Parse(txtCirCntPtY.Text.Trim());
rad = double.Parse(txtCirRadius.Text.Trim());
}
return this.Init_Circle(pt,rad);
}
You can't return anything from the constructor, but what you can do is create a static method that creates the object for you.
So in your constructor do it like this.
private Init_Circle()
{
}
and create a method like this
public static Init_Circle CreateInstance(// parameters here)
{
// do object creation here
}
You should create a method which will returns object. You can't return anything in a constructor.
Method should look like this:
public Init_Circle ReturnCircle(Point pt,double rad)
{
Point center=pt;
if (rbCircle.Checked==true)
{
pt.x = double.Parse(txtCirCntPtX.Text.Trim());
pt.y = double.Parse(txtCirCntPtY.Text.Trim());
rad = double.Parse(txtCirRadius.Text.Trim());
}
return this.Init_Circle(pt,rad);
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I Want to know that i have define a function in form
Eg:Dynamically Display (Running) Current Date Time
It display the current system time on that form
Is it possible to call the same function without creating a new function on each and every form?
please help
Solution 1: You dont need to write a function for this:
Label1.Text = DateTime.Now.ToString();
Solution 2: but if you want to access it using function create a static function
public static class Utility
{
public static string DisplayDateTime()
{
return DateTime.Now.ToString();
}
}
Call the above function wherever you want as below:
Label1.Text = Utility.DisplayDateTime();
Solution 3: if you want to change datetime for every second try this:
public static class Utility
{
public static string DisplayDateTime()
{
return DateTime.Now.ToString();
}
}
System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
timer1.Interval=1000;//one second
timer1.Tick += new System.EventHandler(timer1_Tick);
timer1.Start();
private void timer1_Tick(object sender, EventArgs e)
{
//do whatever you want
Label1.Text = Utility.DisplayDateTime();
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Ho do you get the current instance of a class?
The class have search method and cancel method.
Code example:
if (btnSearch.Text =="Search")
{
Searcher srch = new Searcher();
srch.Search();
btnSearch.Text = "Cancel";
return;
}
if (btnSearch.Text == "Cancel")
{
//call a method in the instance above for example
srch.Cancel();
}
I want to create the instance only when btnSearch.Text =="Search"; and when btnSearch.Text =="Cancel"; i want to call srch.Cancel();
////
Thanks to nmclean, problem solved, makes sense i had to declare the Search class at a higher scope to be able to access the current running instance.
Your srch variable must be declared at a higher scope than the function, otherwise it will not persist to the next time the function is called. Most likely this means it should be a field of the class:
class YourClass
{
private Searcher srch;
void YourMethod()
{
if (btnSearch.Text == "Search")
{
srch = new Searcher();
srch.Search();
btnSearch.Text = "Cancel";
return;
}
if (btnSearch.Text == "Cancel")
{
srch.Cancel();
}
}
}