|
Consider generic types with the same name, like Tuple.
You could put
Tuple, Tuple<T>, Tuple<T1, T2> , etc in separate files (Tuple.cs, Tuple`1.cs, Tuple`2.cs), but it's acceptible to put them in one file.
|
|
|
|
|
I have disabled the button on form load. Then I want to enable it when a condition is accomplished, but something's wrong and i can't figure it out what exactly. Conditions are accomplished but button is still disabled.
private void button1_EnabledChanged(object sender, EventArgs e)
{
if (textBox1.Text != "" && textBox2.Text != "" || textBox3.Text != "")
if(ok)
button1.Enabled = true;
}
|
|
|
|
|
You're changing the buttons enabled state in the enable state changed event handler. That doesn't seem right to me. Also, you might want to check your and/or logic in the text box checks.
|
|
|
|
|
So there is no method that I can use it for this? I can enable the button from another function after I check those conditions, but I wanted to do it in this way..
|
|
|
|
|
This looks like WinForms to me. If so, you can use a technique like this[^] to accomplish what you want.
|
|
|
|
|
Aaaa yes, sorry. Is WinForm. Thanks, I'll check it right now
|
|
|
|
|
The task you describe can be approached in several different ways:
I. You could have very specific implementations of each "rule" for each change in "UI state;" for example, you could view the criteria for setting 'button1 to enabled as being dependent upon three TextBoxes all having content that is not string.Empty.
Which means you will have to have event handlers of some Form monitoring the changes in content in the three TextBoxes.
II. You could implement a "generic" strategy for controlling Control properties like 'Visible, 'Enabled (or any other properties) which would contain the data for the settings of each Control's properties in a number of "states:" i.e., a "state machine" approach.
Let's say I defined several "methods" (using Func<>) to express different possible states of the three TextBoxes:
private Func<bool> AllEmpty;
private Func<bool> AllFull;
private Func<bool> AnyEmpty;
private Func<bool> CurrentTextBoxTest;
private void Form1_Load(object sender, EventArgs e)
{
AllEmpty = new Func<bool>(() =>
{
return textBox1.Text == string.Empty && textBox2.Text == string.Empty && textBox3.Text == string.Empty;
});
<pre>
AnyEmpty = new Func<bool>(() =>
{
return (textBox1.Text == string.Empty || textBox2.Text == string.Empty || textBox3.Text == string.Empty);
});
AllFull = new Func<bool>(() => {! AnyEmpty() });
CurrentTextBoxTest = AllFull;
}
And I wired-up the same 'Leave EventHandler, named 'TB_Leave,' to the three TextBoxes, defined like this:
private void TB_Leave(object sender, EventArgs e)
{
if(CurrentTextBoxTest != null) button3.Enabled = CurrentTextBoxTest();
} In this case, the contents of 'CurrentTextBoxTestState would be 'AllFull: so the button would be enabled only if all three TextBoxes had content.
If the UI then "moved" to a "state" where the content of those three TextBoxes should have no impact on 'button1's current Enabled state: then I'd just set the 'Func CurrentTextBoxTest to null.
If the UI then "moved" to a "state" where all TextBoxes being "empty" meant the Button should be enabled: I'd set 'CurrentTextBoxTestState to 'AllEmpty.
Note that I'm not saying you should implement some kind of "formalism" for UI state control ... as described here ... for any given project.
The point it becomes worth the time and effort to implement such a formalism is, imho, when you have a complex UI with several possible state changes, and various complex dependencies of Controls on the state of other Controls.
Other "tools" for dealing with UI state change include dynamically moving, and/or restoring, Control EventHandler definitions depending on state.
Another strategy (which I have implemented in the past) involves keeping a Dictionary<Control, List<ControlState>>, where 'ControlState in the 'ControlState List contains data (like values for 'Enabled, 'BackgroundColor, etc.) per state, and/or an executable Function. The idea being that for all Controls that have a special "marker" (Attribute, Tag, etc.) a "state controller" can take a state index as an input, traverse the Dictionary, pull out the matching state, and apply it.
I am not familiar with using the IExtender Provider mentioned by Pete, but look forward to studying it.
«To kill an error's as good a service, sometimes better than, establishing new truth or fact.» Charles Darwin in "Prospero's Precepts"
|
|
|
|
|
The Button1_EnableChanged event doesn't fire until Button1.Enabled = true; executes. Hence, Button1.Enabled = true; must go into another method, such as, for example, the method that detects the change that makes it appropriate to enable the button.
As an example, if I have a routine that has a TextBox1_TextChanged event that evaluates the Text property of TextBox1 , and determines that its new value warrants enabling Button1 , it does so by setting its Enabled property to True .
|
|
|
|
|
I use RouteCollection with FriendlyUrlSettings to remove aspx from being shown... so now every time someone access my site, instead of display www.mysite.com/login.aspx , it will display www.mysite.com/login
But I have a problem where an old app needs to access a page, and it's already hard-coded inside the app to access www.mysite.com/service/AuthenticateUser.aspx page. But because of the friendlyurl, the app doesn't work.
So I added this line
routes.Ignore("Service/AuthenticateUser.aspx");
but it doesn't seem to do anything. Every time I access the page Service/AuthenticateUser.aspx , it will still redirect me to Service/AuthenticateUser only
|
|
|
|
|
How about asking this in the ASP.NET forum as it has nothing to do with C#.
|
|
|
|
|
err... why is this a asp.net question? As per my understanding, the codes that handles the ignoring of specific file or folder needs to be written in the back code (c#) in my case.
public static void RegisterRoutes(RouteCollection routes)
{
routes.RouteExistingFiles = false;
routes.Ignore("SERVICE/{*pathInfo}");
var settings = new FriendlyUrlSettings();
settings.AutoRedirectMode = RedirectMode.Permanent;
routes.EnableFriendlyUrls(settings);
}
the code above is what I did but still doesn't work
|
|
|
|
|
Because you're asking about the functionality of ASP.NET and/or possibly MVC routing.
|
|
|
|
|
Hello there. I am given a small xml script. How can I use that script to change the frame rate of this IP camera. Thanks for any input.
|
|
|
|
|
The question is not clear. Please explain what C# issues you are having problems with.
|
|
|
|
|
Well, I would say that you need to read some value from your XML file. It will either be an attribute or an element. Oh wait, it might be a set of values that you use to calculate the rate. If it is, you will have to read the values in and apply whatever calculation is appropriate. However, unless I'm greatly mistaken, IP cameras don't use framerates - they use bandwidth, and while you may be able to change the frame rate, the underlying bandwidth might not be able to cope.
As for actually choosing a frame rate and displaying your images then why not look at Aforge and set the DesiredFrameRate[^].
|
|
|
|
|
I have a textBox where i want to insert a string in a licence model (fdsf-dfss-fdfd-fdhd). I tried to select first 4 char and when I have 4 chars, is inserted "-". But it starts from the beginning when "-" is inserted after first 4 chars. This is how I tried:
private void textBox4_TextChanged(object sender, EventArgs e)
{
for (int i=0;i<=textBox4.Text.Length;i++)
{
while (textBox4.Text.Length == 4)
{
textBox4.Text += "-";
}
}
}
How can I make like after I have 4 chars and "-" is inserted, to be able to continue inserting the text after "-" ?
|
|
|
|
|
|
|
Change it to:
textBox4.Text += "-";
textBox4.SelectionStart = textBox4.Text.Length;
..in order to set the input cursor to the end of the text again.
Unrelated suggestion: Give your TextBoxes and all other controls a name that explains their purpose - in this case maybe "LicenceInput". That will make it much easier to read your code, even for yourself, after you haven't worked on it for a while
edit: A MaskedTextBox might be the most convenient way to handle this. The input mask would be: 0000\-0000\-0000\-0000
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
modified 20-Apr-15 7:15am.
|
|
|
|
|
it works, but after I insert another 4 characters, "-" is not inserted.
|
|
|
|
|
Please edit your original post and add your reworked code in a second code-block.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
On second thought, the modulo operator-approach isn't really well suited here, because due to inserting the dashes, the length of the text won't be a multiple of 4 at the positions where the next dash should be inserted. I would recommend a MaskedTextBox instead with an input mask like 0000\-0000\-0000\-0000
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I can insert only numbers..
|
|
|
|
|
|
Is ok, I solved it. Thank you !
|
|
|
|