So, I'm losing my mind over a bug in my software.
I have this code, I use it 2 times in my software, the other function similar (with a different name) works normally. But this one is inverted...
I mean by that : Instead of enabling the controls when the groupbox.text contains "INC", it disable them.
Any idea on what is going on?
`private void Enable_disableSTM()
{
if (STM_groupBox.Text.Contains("INC"))
{
STM_radioButton_appel.Enabled = true;
STM_radioButton_autre.Enabled = true;
STM_radioButton_resolution.Enabled = true;
STM_Textbox_SR.Enabled = true;
STM_textBox_remarque.Enabled = true;
STM_Dropdown_Sendto.Enabled = true;
STM_pictureBox_Boutonenvoyer.Enabled = true;
}
else
{
STM_radioButton_appel.Enabled = false;
STM_radioButton_autre.Enabled = false;
STM_radioButton_resolution.Enabled = false;
STM_Textbox_SR.Enabled = false;
STM_textBox_remarque.Enabled = false;
STM_Dropdown_Sendto.Enabled = false;
STM_pictureBox_Boutonenvoyer.Enabled = false;
}
} `
Edit :
Like I said, in my software I have this other function that is working fine. I tried also to change my IF to STM_Textbox_reademail.Text != "" and it's still not working correctly. It's inverted. Enabling when it should not and Disabling too.
`if (SQ_TextBox_reademail.Text != "")
{
SQ_radioButton_appel.Enabled = true;
SQ_radioButton_autre.Enabled = true;
SQ_radioButton_resolution.Enabled = true;
SQ_Textbox_SR.Enabled = true;
SQ_textBox_remarque.Enabled = true;
SQ_Dropdown_Sendto.Enabled = true;
SQ_pictureBox_Boutonenvoyer.Enabled = true;
}
else
{
SQ_radioButton_appel.Enabled = false;
SQ_radioButton_autre.Enabled = false;
SQ_radioButton_resolution.Enabled = false;
SQ_Textbox_SR.Enabled = false;
SQ_textBox_remarque.Enabled = false;
SQ_Dropdown_Sendto.Enabled = false;
SQ_pictureBox_Boutonenvoyer.Enabled = false;
} `
Edit 2 : Okay... I figured out something that works. I'm calling my function at a different place now and it's working. Still does not make sense why I can call the other one at the same place and it works but this one doesn't... but hey... now it works! thanks all!
Your problem is that you are checking if a string contains the "INC" word in a case sensitive way the solution is changing the if statement to check in the string the inc word ignoring the case :
private void Enable_disableSTM()
{
if (STM_groupBox.Text.IndexOf("INC", StringComparison.OrdinalIgnoreCase) >= 0;)
{
STM_radioButton_appel.Enabled = true;
STM_radioButton_autre.Enabled = true;
STM_radioButton_resolution.Enabled = true;
STM_Textbox_SR.Enabled = true;
STM_textBox_remarque.Enabled = true;
STM_Dropdown_Sendto.Enabled = true;
STM_pictureBox_Boutonenvoyer.Enabled = true;
}
else
{
STM_radioButton_appel.Enabled = false;
STM_radioButton_autre.Enabled = false;
STM_radioButton_resolution.Enabled = false;
STM_Textbox_SR.Enabled = false;
STM_textBox_remarque.Enabled = false;
STM_Dropdown_Sendto.Enabled = false;
STM_pictureBox_Boutonenvoyer.Enabled = false;
}
}
Okay... I figured out something that works. I'm calling my function at a different place now and it's working. Still does not make sense why I can call the other one at the same place and it works but this one doesn't... but hey... now it works! thanks all!
Related
I am trying to make a copy of the answer from this question here: Xamarin iOS: Auto Layout within scroll view? but without using the interface builder. The code is simple, I have _scrollView which has background color green. Then I have _contentView which has background color red. I add _contentView to _scrollView and I add _scrollView to View in the ViewController. When I run this, all I get is Green controller, the red one never appears inside of it.
public async override void ViewDidLoad()
{
base.ViewDidLoad();
//ui
View.BackgroundColor = UIColor.White;
//views
_scrollView = new UIScrollView();
_scrollView.BackgroundColor = UIColor.Green;
_scrollView.TranslatesAutoresizingMaskIntoConstraints = false;
_contentView = new UIView();
_contentView.TranslatesAutoresizingMaskIntoConstraints = false;
_contentView.BackgroundColor = UIColor.Red;
var label = new UILabel();
label.TranslatesAutoresizingMaskIntoConstraints = false;
label.Text = "Text";
_contentView.AddSubview(label);
_scrollView.AddSubview(_contentView);
View.AddSubviews(new UIView[] { _scrollView });
_scrollView.TopAnchor.ConstraintEqualTo(View.TopAnchor, 100).Active = true;
_scrollView.LeftAnchor.ConstraintEqualTo(View.LeftAnchor, 20).Active = true;
_scrollView.RightAnchor.ConstraintEqualTo(View.RightAnchor, -20).Active = true;
_scrollView.BottomAnchor.ConstraintEqualTo(View.BottomAnchor, -100).Active = true;
_contentView.TopAnchor.ConstraintEqualTo(_contentView.Superview.TopAnchor).Active = true;
_contentView.RightAnchor.ConstraintEqualTo(_contentView.Superview.RightAnchor).Active = true;
_contentView.LeftAnchor.ConstraintEqualTo(_contentView.Superview.LeftAnchor).Active = true;
_contentView.BottomAnchor.ConstraintEqualTo(_contentView.Superview.BottomAnchor).Active = true;
_contentView.WidthAnchor.ConstraintEqualTo(_contentView.Superview.WidthAnchor).Active = true;
label.TopAnchor.ConstraintEqualTo(label.Superview.TopAnchor, 100).Active = true;
label.BottomAnchor.ConstraintEqualTo(label.Superview.BottomAnchor, 100).Active = true;
label.LeftAnchor.ConstraintEqualTo(label.Superview.LeftAnchor, 100).Active = true;
label.RightAnchor.ConstraintEqualTo(label.Superview.RightAnchor, 100).Active = true;
}
You need to constraint the width of the _contentView to the View instead of _scrollView. Change this constraint:
_contentView.WidthAnchor.ConstraintEqualTo(_contentView.Superview.WidthAnchor).Active = true;
For this one:
_contentView.WidthAnchor.ConstraintEqualTo(View.WidthAnchor).Active = true;
Other than that I highly recommend you to use a helper library for using AutoLayout programatically. Check out FluentLayout
The only way I was able to make it work was by adding BottomAnchor to the last UIView inside ContentView. I created a GitHub repo with demo code here
I had long time developing windows applications using VB.NET and one of thing that I was always use is:
Class (Test) and inside it there are some subs like the following:
VB.NET Code
Friend Sub FLoadKeyLock(ByVal FRMNAME As Object)
FRMNAME.Button3.Enabled = true;
FRMNAME.Button4.Enabled = true;
FRMNAME.Button1.Enabled = false;
FRMNAME.Button2.Enabled = false;
FRMNAME.Button5.Enabled = false;
FRMNAME.Button6.Enabled = false;
FRMNAME.Button7.Enabled = false;
FRMNAME.Button8.Enabled = false;
FRMNAME.Button9.Enabled = false;
FRMNAME.Button10.Enabled = false;
End Sub
Where FRMNAME refers to forms name that I send from different forms and I use (me) keyword to send current form name to apply that sub.
That was totally works fine in VB.NET but I cannot use it the same way in C#.NET.
C#.NET Code
internal void FLoadKeyLock (Form FRMNAME)
{
FRMNAME.Button3.Enabled = true;
FRMNAME.Button4.Enabled = true;
FRMNAME.Button1.Enabled = false;
FRMNAME.Button2.Enabled = false;
FRMNAME.Button5.Enabled = false;
FRMNAME.Button6.Enabled = false;
FRMNAME.Button7.Enabled = false;
FRMNAME.Button8.Enabled = false;
FRMNAME.Button9.Enabled = false;
FRMNAME.Button10.Enabled = false;
}
The Error is: System.Windows.Forms.Form' does not contain a definition for 'Button3' and no extension method 'Button3' accepting a first argument of type
And same error for all used buttons.
So I have two questions:
1 - How to use such a function in C#.NET?
2 - Why it's not working the same way as VB.NET?
As #Maarten said.
dynamic has solved my problem
internal void FLoadKeyLock (dynamic FRMNAME)
{
FRMNAME.Button3.Enabled = true;
FRMNAME.Button4.Enabled = true;
FRMNAME.Button1.Enabled = false;
FRMNAME.Button2.Enabled = false;
FRMNAME.Button5.Enabled = false;
FRMNAME.Button6.Enabled = false;
FRMNAME.Button7.Enabled = false;
FRMNAME.Button8.Enabled = false;
FRMNAME.Button9.Enabled = false;
FRMNAME.Button10.Enabled = false;
}
What is needed : I need it to close and reopen the browser, I've tried a couple of things. Winform, c#.
What i've tried :
using (Viewer = new GeckoWebBrowser())
{
Viewer.Dock = DockStyle.Bottom;
Viewer.Size = new Size(217, 257);
Viewer.Location = new Point(0, 90);
Viewer.Enabled = true;
Viewer.Visible = true;
Xpcom.Initialize("xulrunner");
GeckoPreferences.User["browser.xul.error_pages.enabled"] = false;
GeckoPreferences.User["security.enable_ssl2"] = true;
GeckoPreferences.User["security.default_personal_cert"] = "Ask Never";
GeckoPreferences.User["security.warn_entering_weak"] = true;
GeckoPreferences.User["security.warn_viewing_mixed"] = true;
GeckoPreferences.User["dom.disable_open_during_load"] = true;
GeckoPreferences.User["dom.allow_scripts_to_close_windows"] = true;
GeckoPreferences.User["dom.popup_maximum"] = 0;
GeckoPreferences.User["dom.max_script_run_time"] = 0;
GeckoPreferences.User["extensions.blocklist.enabled"] = false;
Viewer.BringToFront();
Viewer.Navigate("http://google.com");
Viewer.Dispose();
}
What is the problem?
It isn't showing up on the winform window.
Also i tried it with a windows control in the winform and using Viewer.Dispose(); destroyed the control completely and i wasn't able to access it any more.
I have a checkbox with event like this:
protected void cbRating1WithoutExceptionP1_CheckedChanged(object sender, EventArgs e)
{
if (cbRating1WithoutExceptionP1.Checked == true)
{
cbRating1WithExceptionP1.Checked = false;
cbRating1WithExceptionP1.Enabled = false;
}
else
{
cbRating1WithExceptionP1.Enabled = true;
}
}
How to call that event from server side?
foreach (string oWithException in oWithExceptions)
{
switch (oWithException.Trim())
{
case "P1":
cbRating2WithExceptionP1.Checked = true;
cbRating1WithoutExceptionP1_CheckedChanged(new object, new EventArgs);
break;
case "P2":
cbRating2WithExceptionP2.Checked = true;
break;
case "P3":
cbRating2WithExceptionP3.Checked = true;
break;
case "P4":
cbRating2WithExceptionP4.Checked = true;
break;
case "P5":
cbRating2WithExceptionP5.Checked = true;
break;
case "NOT_ALLOWED":
cbRating2WithExceptionNotAllowed.Checked = true;
cbRating2WithExceptionP1.Checked = false;
cbRating2WithExceptionP1.Enabled = false;
cbRating2WithExceptionP2.Checked = false;
cbRating2WithExceptionP2.Enabled = false;
cbRating2WithExceptionP3.Checked = false;
cbRating2WithExceptionP3.Enabled = false;
cbRating2WithExceptionP4.Checked = false;
cbRating2WithExceptionP4.Enabled = false;
cbRating2WithExceptionP5.Checked = false;
cbRating2WithExceptionP5.Enabled = false;
break;
}
}
}
Like this:
cbRating1WithoutExceptionP1_CheckedChanged(new object, new EventArgs);
Is that possible to call the event from server side without create a function?
You Like This if You wants to Only Call Your method:
cbRating1WithoutExceptionP1_CheckedChanged(null, EventArgs.Empty);
I'm trying to change an Object's properties from another class, like so.
abilities.cs (class)
public static void hideAllButtons()
{
frmFight fight = new frmFight();
fight.btnAbility1.Visible = false;
fight.btnAbility2.Visible = false;
fight.btnAbility3.Visible = false;
fight.btnAbility4.Visible = false;
fight.btnAbility5.Visible = false;
fight.btnAbility6.Visible = false;
vars.buttonsVisible = false;
}
I'm trying to use the method from the previous class to change the object's properties in the following Form;
frmFight.cs (form)
private void btnAbility1_Click(object sender, EventArgs e)
{
abilities.hideAllButtons();
btnAbilities.Enabled = false;
}
I've tried everything in my knowledge and understanding, and a lot of looking up on the internet. I've tried making the objects static, public, creating the object within the class. But nothing works. Usually I get StackOverFlow errors.
I'm pretty new to OOP, too, but I'm not an idiot so don't think to go too 'lightly' on me with a possible fix, or cause, of my problem - if you understand, that is.
Method hideAllButtons is static so should have a Form argument.
public static void hideAllButtons(frmFight fight)
{
fight.btnAbility1.Visible = false;
fight.btnAbility2.Visible = false;
fight.btnAbility3.Visible = false;
fight.btnAbility4.Visible = false;
fight.btnAbility5.Visible = false;
fight.btnAbility6.Visible = false;
//vars.buttonsVisible = false; // What about this???
}
and call this method in click handler,
hideAllButtons(this);
This really wont work because your controls is on your frmFight.
You need to do is place
private void hideAllButtons()
{
btnAbility1.Visible = false;
btnAbility2.Visible = false;
btnAbility3.Visible = false;
btnAbility4.Visible = false;
btnAbility5.Visible = false;
btnAbility6.Visible = false;
vars.buttonsVisible = false;
}
on your frmFight.cs (form) as private method and just call it on your button click to make it simpler.
private void btnAbility1_Click(object sender, EventArgs e)
{
hideAllButtons();
btnAbilities.Enabled = false;
}
Regards