|
As stated in my reply to BobJanova, i don't use DoEvents() because of a "normal user experience", but because that is the moment I want to handle the instrument-setup events.
My application is an pc-scope application, so indeed it runs "as fast as it can".
|
|
|
|
|
The problem with DoEvents is that you're not just handling your instrument events. You handling ALL events, including your form controls and repaint commands. So if the use clicks a button a second time when they're not supposed to, or changes text, or moves the form, or whatever, those events get handled right along with your instrument events.
DoEvents processes all pending event messages until the message queue is empty. This opens you up to reenterant code possibilities where your code is not written to handle it.
|
|
|
|
|
Just to add to what Dave said, I'm not sure I would trust a scope (PC based or not) that ran "as fast as possible" - that implies that other events in the system are controlling or affecting the sampling rate. Which means that what I see on the "screen" may not be consistent and repeatable. I would much, much rather have a scope that had a slower, known speed so that artefacts become more obviously scope related than hardware.
I have spent too much time trying to find the source of a problem that turned out to be due to variable sampling frequency rather than a hardware or software problem in the target.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Oh, don't worry about that. I use real oscilloscope hardware. So on StartMeasurement(), the instrument is armed, waits for a trigger, and then fills the acquisition record with samples that are captured on a sampleclock. When the measurement is finished, I read the whole record from the instrument's memory to the PC, and re-arm the instrument. So running "as fast as possible" has no influence on the sampling rate.
|
|
|
|
|
Hello,
Am new in Programming and i chose to start with C#. I have an application that am building but am unable to connect my 'Add a member' form to a MySql database. I have created text boxes for first name, last name, phone, city and down there an ADD and CANCEL buttons.
Could someone please give me the code to link the add button to the database such that the information on the text box is sent to the database. Please help out like you doing it to a two year old.
Thanks.
|
|
|
|
|
Member 8624435 wrote: Am new in Programming and i chose to start with C#
Good choice.
Member 8624435 wrote: Could someone please give me the code to link the add button to the database
Nobody will GIVE you code. What did you try? How did you search? Maybe you need other keywords. Try this site[^] for starters. In addition, you don't link the ADD button to the database directly. read up on 'n-tier applications' and you'ld probably want a book to start with.
Member 8624435 wrote: Please help out like you doing it to a two year old.
My son is nearly two, he cannot read or write yet, let alone program. We assume you have a certain level of intelligence.
In summary:
- Start with a book and read it from first to last page.
- Don't post anything like 'give me code' and the likes. You must do the effort. people here only guide or advice you.
- The tone of your question is wrong and might be downvoted by others. (just for info)
Hope this helps.
V.
|
|
|
|
|
Rather than asking for the code you should try doing some research, try typing your question into a google search. Any basic question will have been answered 1000s of times and you can use them to begin your research.
Do not rely on this as your only source of knowledge, buy a book, it will give you some structured learning.
When you have a specific problem with something then come back with the code that is giving you a problem and you'll find this site much more useful.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
i want to access my other forms when i click the button from one form.... can anyone tell how to access the other forms in c#.????
|
|
|
|
|
You can use delegates to communicate between forms.
Here[^] is a decent example.
|
|
|
|
|
Well there are multiple methods. Another approach can be
- make a static class and define its data/function members
- set values of data member of this class from Form2.
- access this static class in Form1.
- Before setting (or after getting) values, you can clear all the values of static class.
It all depends on situation. Once delegates did not work for me so had to use this method
|
|
|
|
|
thanks for your useful info....
|
|
|
|
|
A key piece of information here is how the Forms are created. If there is one primary Form that creates, and Shows, the other Forms, then, at the point where you create the secondary Forms, you have a reference to that newly created Form.
That means that if you do this in your main form:
Form2 F2 = new Form2(); And you define the variable 'F2 as being within the scope of the main form: you can always access the instance of Form2, 'F2, within the main form: once you have instantiated it ... most likely in the main Form Load EventHandler.
The question that you should be asking yourself now is: "wait a minute, 'F2 has a TextBox on it, and that TextBox is an access-as-private-only Control: it can't be seen using the reference to 'F2: this won't work:
Form2 F2;
TextBox TextBoxOnForm2;
private void Form1_Load(object sender, EventArgs e)
{
F2 = new Form2();
F2.Show();
TextBoxOnForm2 =
} And this is the point at which I encourage you to start thinking about the issue of "what is the bare essential content, or control, that one Form needs to access from another ?: does it need to only access content in the Control, or does it need access to the Control itself so that it can modify the content of the Control, and/or its settings, or visual appearance, or whatever."
In this case it appears you want access to either a TextBox itself implying you might want to both read from and write to the TextBox perhaps make changes to its structrure: probably, at least, access the contents of the TextBox.
Let's take the case where you want full access to the TextBox on the instance of Form2, 'F2:
1. first define a public property in Form2 of Type TextBox:
public TextBox F2TextBox
{
private set;
get { }
} 2. then in the Load or Shown events of Form2: set that public property to the instance of the TextBox: so your code in Form2 might look like this:
public TextBox F2TextBox;
private void Form2_Load(object sender, EventArgs e)
{
F2TextBox = textBox1;
} And now in your main form, you no longer need to keep a reference to the whole instance of Form2; you just need access to the TextBox on Form2:
public TextBox TextBoxOnForm2;
private void Form1_Load(object sender, EventArgs e)
{
Form2 F2 = new Form2();
F2.Show();
TextBoxOnForm2 = F2.F2TextBox;
} Now you have access to the TextBox itself: you can manipulate its Size, BackGroundColor, whatever, an access its Text by TextBoxOnForm2.Text
And if you want to get the current content (Text) in the TextBox on F2 "on demand," for example,, by a Button Click EventHandler on the main form:
private void button1_Click(object sender, EventArgs e)
{
SomeTextBoxOnForm1.Text = TextBoxOnForm2 .Text;
} What if you need to instantly synchronize any change in the Text on F2 with other Text somewhere on the main Form: then you are going to have to define a Public Event that accesses F2's TextBox, and Raises that Event with each change in the Text in the TextBox on the instance of Form2: the main form will then have to "subscribe" to that Event. The answer above by Abhinav points you to the use of Delegates to help you with that.
There are other ways, also, to approach "access to control and/or data" between Forms, like the use of Interfaces, and Static classes.
And we could re-write this example so the only thing you could get access to on Form2 was the actual Text content of the TextBox, not the TextBox itself, but we'll leave that for you to think about. But, here's a hint: the public Property defined on Form2 is now going to look something like this:
public string F2TextBoxText
{
set { textBox1.Text = value; }
get { return textBox1.Text; }
}
"The first principle is that you must not fool yourself, and you are the easiest person to fool." Richard Feynman
modified 8-Feb-12 9:36am.
|
|
|
|
|
hellog guys...plz excuse me for this basic question. I have these three comboboxes on the form. They are bound to a common DataTable. Now when I change value of one combobox, values of other two are also changed. So in essance, every time I make change to one of the combo boxes, all of them point to same value in datatable. What can be the reason? Ask me if you need code. thnx
|
|
|
|
|
If you copy pasted these dropdowns, most likely the datasource and the binding properties have been copied too.
Check the data sources and three properties you have bound to.
|
|
|
|
|
Actually I am setting values of all the dropdowns in the same functions, so I had to copy/paste the code. Here is the code
<pre lang="c#">
private void LoadStudents()
{
StringBuilder sb = new StringBuilder();
DataTable dt = GetStudentsList(); //get data from database
DataTable dt2 = MakeTable(); //to insert concatenated NAMEs with IDs
for (int i = 0; i < dt.Rows.Count; i++)
{
// concatinate id with name
sb.Append(dt.Rows[i][0].ToString().Trim());
sb.Append(" --- ");
sb.Append(dt.Rows[i][1].ToString().Trim());
string studentName = sb.ToString();
dt2.Rows.Add(studentName );
sb.Clear();
}
LoadAccountsIntoCombos(dt2);
}
private void LoadAccountsIntoCombos(DataTable dt2)
{
//Show Students
combo1.DataSource = dt2;
combo1.DisplayMember = "StudentName";
combo1.SelectedIndex = 0;
combo2.DataSource = dt2;
combo2.DisplayMember = "StudentName";
combo2.SelectedIndex = 0;
combo3.DataSource = dt2;
combo3.DisplayMember = "StudentName";
combo3.SelectedIndex = 0;
}
</pre>
|
|
|
|
|
I think (it has been a while since I used a datatable) you can use something like
combo2.DataSource = dt2.Copy();
Basically you need to make a copy of the datatable so you are not continiously interacting with the same data.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: combo2.DataSource = dt2.Copy();
That sounds perfect.
|
|
|
|
|
Thnx..it helped...hence voted
|
|
|
|
|
In short, you assigned the same 'reference' to the comboboxes. You need to have a 'deep copy' assigned to them. (I also used to make that same mistake )
V.
|
|
|
|
|
Bear in mind that this copies the entire data table, which is often vast overkill for a combo box. In this case the table appears to be just ID/value so this is probably a correct solution, but the questioner shouldn't take away that this is something that should be applied to all data binding scenarios.
|
|
|
|
|
Generally (I love generalisations) a combo table tends to be small. However one must expect some common sense to be applied to any solution. The OP was chasing the problem of using the same datasource, the size of the datasource was not part of the problem
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Indeed, the copying is fine for this problem. I just wanted to raise the issue so the next time this guy wants to do something similar he might be reminded to think about it.
|
|
|
|
|
You should not duplicate the data, instead you should use an explicit BindingSource (DataContainer -> BindingSource -> Control ), that way each binding would be distinct, and would hold its own state.
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
This is the best solution and follows DRY principle. to Luc Pattyn
|
|
|
|
|
how to get names and count of tables in a database from sqlserver and MSAccess?
could u tell me pls?
|
|
|
|