In the designer view of the form (not the code-file), click on the top of the form. In the properties windows, the form itself will now be selected. Amongst all properties of the form, you have one which is called AcceptButton (my mistake, I gave you a wrong name); set this one to the name of the OK button (you can select it). When that is done, you no longer need to write an event-handler (a method) for the button's click event; the framework will wire up everything and on click of the button the form will be hidden and return DialogResult.OK.
Learning is much easier and fun when people like you guys, help people like me out. I was ripping my hair out yesterday trying to figure out how to a value from one form to another.
Is the code that Phil.o supplied classed as an event?
You mentioned above that - Delegates aren't "the best way" to pass variables back, Events are (which use delegates, but hides the complexities from you).
No - that's just using ShowDialog to display Form2, which causes the Form1 code to "freeze", waiting for the new form to close before executing any more code (this is technically called a "Modal Form" but you don't need to worry about it).
There is also Form.Show which returns immediately, and that type needs Events to "Know" when data is available for Form1 to process. Follow the link I gave you, and you'll find a download of a source project that shows it all working with Show.
If you are going to use Events - and it's a good idea, .NET is built on the buggers - then also have a look here: A Simple Code Snippet to Add an Event[^] - it makes it a lot easier to create them in your own forms and other classes.
Sent from my Amstrad PC 1640 Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
I want to write a PowerPoint addin that adds a button to the screen during the actual presentation time (rather than editing time) and then draws output on top of the presentation over top the presentation. The point is to pick a random person from a registered audience and display their name.
1. Is this kind of thing possible?
2. I know there are interop pages available online. Does anyone have any quick pointers as to what part of these documents I should look at for presentation event handlers (such as a slide change) and stuff like that? Perhaps how to draw a GDI+ object to a slide? (and remove that drawing upon a button click)?
No... actually this is the correct forum. I am interested in C# addons. Not whatever that is about. There is already a tutorial on basic .NET addons but it doesn't quite cover the areas I am interested in learning about:
I'm trying to create a query with And and Or predicates.
My question is how to form it so that I have all the ANDS, PLUS the ORs:
If this was SQL, I would do
WHERE InstrumentId = 1 AND
BaySerialNumber = 'ABC123' AND
AssayType = 'MyType' AND
(ValdityCode = 'Code1' OR
ValdityCode = 'Code2' OR
ValdityCode = 'Code3')
Note that the codes are in parens.
Here's what I have so far:
// Create the predicate
var predicate = PredicateBuilder.New<ValidityRulesEntity>();
// Add the Instrument, Bay Serial Number, and Assay Type
predicate = predicate.And(x => x.InstrumentId == entity.InstrumentId);
predicate = predicate.And(x => x.BaySerialNumber == entity.BaySerialNumber);
predicate = predicate.And(x => x.AssayType == entity.AssayType);
// Now add the codes from the list. This should be in ADDITION to the above conditions.
foreach (var validityCode in entity.ValidityCodes)
predicate = predicate.Or(x => x.ValidityCodes.Equals(validityCode));
What's the right way to do this?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
I have a asp form what I want if the form validation is true then the page should be refresh and all the fields should be clear and if the validation is not true the page should not be refresh and the form data should not be cleared.
You still "refresh" on error; except, you "return" all the data, with appropriate "error info", so the user can correct.
A favorite seems to be to say there are errors and to return an empty screen so you can start over (sloppy banks and insurance companies). Oh, and don't forget to timeout in a ridiculous short amount of time; like, too short, to check some papers (the first time).
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
If I make a new project in Visual Studio and give it the name Welcome Program, then I see this in the code window:
namespace Welcome Program
Okay I am aware that a namespace helps organize things better and helps keep things separate, but this is not needed in a console program. But if I delete this line in a GUI program the program will not build. Is this just simply something Microsoft decided to build into their language? It has to be there when making a GUI?
And my second question is about this line:
Public Partial Class MainWindow:Window
All I know about this is that a partial class allows you to split the class definition among more than one file. This line also has to be there. What does MainWindow:Window mean? What is the purpose of the colon?
'NameSpaces [^] control semantic scope: the context in which specific names (Classes, Methods, Fields, Properties, etc.) have meaning. They are a tool you can use to organize your code, and, when using different libraries that have duplicate names, to ensure isolation of one meaning from another (prevent name clashes).
Going a little "deeper:" we can view NameSpaces as an abstraction of an underlying code base that involves Assemblies; see this to explore this further: [^]
C# allows multiple NameSpaces in one file; other languages (ex. Java) do not.
It is very typical to use 3rd. party tools, or code libraries (dll's), and typical that you need to import code which will have their own NameSpaces. In C# Visual Studio you do this from the Solution/Project/References/Add Reference menu in the Solution Explorer.
Then, you enable the imported code to become available by adding a 'using statement with the name of the NameSpace.
Member 12974235 wrote:
Public Partial Class MainWindow:Window
This is the default declaration of a newly created WPF app.
Partial Class Form1
This what the Designer.vb file in a VB app uses.
public partial class Form1
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
Last Visit: 31-Dec-99 18:00 Last Update: 29-Jul-21 10:04