|
Hello Dave and Thank You very Much,
I understand and agree with you completely but I am taking an inverse approach due to my apps functionality. I am creating a SendKeys keyboard emulator which will have a pre compiled set of universal buttons all referenced by the simple button1-n name. I will have an excel config file with the button’s parameters (visibility, location, size, text, colors.... and key code) which will be loaded for each application I want to keyboard emulate. Instead of having to have multiple form layouts and keycodes for each interface application I will have a simple excel file to copy cut and paste parameters.
So from my excel config I can set number and string parameters but I can't store and retrieve object oriented parameters (def?), I have to store & retrieve them as strings.
The problem that hangs me up is when I have a parameter such as FlatStyle with has arguments of Standard, Flat, PopUp... that are not strings but some type of object property. So when I need to retrieve PopUp as a string I need to convert it to a type of object property.
var TypeOfStyleObject = convert-this-string-to-what-FlatStyle-wants("PopUp"); // PopUp will actually be a StringArray[x]
button1.FlatStyle = TypeOfStyleObject;
I studied the link you pointed out and it solved my problem, with an exception. I fetched the name of the CONTROL (not a specific control like Button) and changed my function input from BUTTON to CONTROL. It passed without error but I did find a catch....
In the function that I apply the configuration parameters to the generic buttons I successfully applied Text, BackColor, ForeColor as a quick test. When I was passing the Button control I was setting FlatStyle but getting a string to object error (above). Now that I am passing the Control control it is saying my "Control" does not have a parameter FlatStyle. I am interpreting this way..... the Control lets me work without specifying the type of object(button, label, RTBox) but I may lose access to some parameters??? Accurate??
I may need to still find a way of passing specific controls instead of generic control object so I don’t lose configurability. I could follow your lead of preloading a Button[] object array and trying see if I can use its index as an object.
Am going anywhere but backwards or circles…… I assuming there has to be some methods that allows you to convert-this-string-to-what-AnyObject-wants() so objects can be acted on in loops and sequences. You have to be able to store & retrieve non numeric config info (strings) that represent object.string.parameterss!!!!! read them & convert to string, save, retrieve, convert string back to object.
Thank You Again………….
|
|
|
|
|
If you look at the documentation for all these features you will see that they invariably have a numeric value which you can pass to the constructor, or set dynamically.
|
|
|
|
|
Your control is (still) also a button, and you can test for that using "is" and "as", and switch between them.
https://stackoverflow.com/questions/3786361/difference-between-is-and-as-keyword
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Thank You to Everyone ,
Your time is valuable and I appreciate it…………
I don’t comprehend ‘yet’ why when I pass a Button reference, I have a parameter to modify but when I pass it as a Control I’m told this parameter is no longer available, at the top level. I do understand there are other hooks into the control I haven’t learned yet.
The reality of the matter is I stepped on a puddle and found out it was a pot hole, I’m sailing in unfamiliar waters. I am a self-taught C#’er with a background from Verlog FPGA and C firmware with no one local to tutor me. I started writing GUI’s in order to aid and test FPGA and firmware code development plus the automation of production testing.
I’ve gotten away so far by walking around the ‘object mountain’ and I’ve reached a point I need to climb it. I have a strong background in state machine development and implementation, I just need to up the game on ‘objects’. I’m pretty good at making a big snow ball if I can figure out which direction to roll down the hill………..
As can been seen from my post I lack the vocabulary………… I was searching for Button when I should have been researching Controls. I fully comprehend the feedback I am getting but I’m lost in the implementation. Not having a full vocabulary in object language can you point me to a youtube series that would be a good launching point for me at my current level of comprehension. I find a free-flowing mind on video conveys more implementation guidance than a rigid text of facts.
A finger pointing in the right direction is all I really need…………..
Thank You Again for your time and help…….
|
|
|
|
|
Everything in c# (.NET) is an "object".
You then add dressing (a class) and turn it into something else. Add another class and make a composite of what came before. But it is still an "object" and also whatever comes after; you're just putting on and taking off diffferent coats. That's "inheritance" ... one of the "3 pillars" of OOP.
That, and understanding "value types" versus "reference types" ("pointers" to "objects" or functions) allow you to model just about anything in software.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Is that the essence of “wrapping”?? I have seen that term with a few libraries I have fiddled with from GitHub.
“understanding "value types" versus "reference types" ("pointers" to "objects" or functions)”
That sounds like the perfect search phrase to get me started………….
Thanks Again…………..
|
|
|
|
|
"Wrapping" (which is a "design pattern") is intentionally "hiding" one object by wrapping it with another in order to protect or facilitate certain features; not the same as "inheriting" which "adds" functionality.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Sounds a lot like a decorator pattern. Do you despise it? I mean, I do like adding functionality by using a decorator, and the .NET framework apparently too, as there are a lot of places where we use them.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I said a wrapper can hide or "facilitate"; which is a good thing. I wrapped a C++ "animation" engine in a FoxPro dll so I could generate 3rd graphics using FoxPro. I did it to earn a license that normally cost $8,000. (A "long" time ago). I could create and race a buggy over 3D terrain ... The ultimate plan was to use the graphics engine in my "rail car repair system", but that's another track.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
A "decorator" is usually there to add functionality?
Gerry Schmitz wrote: I could create and race a buggy over 3D terrain Now there is some code I'd like to read and learn from
I'm really bad at making games, I do forms and databases.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I'm sure, with a bit of lateral thinking, you could make a game out of form filling.
|
|
|
|
|
Way off topic; I'll try. If I succeed, it will become a new article.
..I just never looked at it that way; it is a game, not a form. Input is input, regardless where it comes from?
Thank you for making my day
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
What is a "game"?
I was a Windows Form evangelist because WPF didn't have a data grid at the time. Then WPF ... I now use UWP because it gets me in the Store, for one thing. (But now any exe can be added to the Store.)
My game consists mostly of moving rectangles around and measuring angles and distances. "Gettysburg!" It's under "Books and References" so I don't pay the "game premium".
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Codice Fictor wrote: Simply put, how would I research and find the solution for these types of problems:
The general problem is that you need to map one value to another value.
The specifics of the values for each is not really relevant. The process however, obviously, is.
Being a bit more specific to your problem you want to map a 'string' (text) to something.
I can't actually tell what you want to map to. But lets say, for example, that it is enum.
Then there are two choices.
1. The string must match the name of the enum exactly. You can get by without case sensitivity but otherwise it must be the same.
2. You MUST provide code that maps from the string to the enum.
Note that there are NO other choices. Pick one.
Lets say you want to pick 1. Then you cannot name a key 'A Key' because a space is not something that can appear in a enum name. You can google for how to convert from string to enum and back again.
Or if you pick 2. There are various ways to do this. But one way actually ends up looking like solution 1. So for example you would have a table that looks like what I posted below. You would read it then match the first value. Then use the second value to create an enum (like I said similar to 1.)
'A Key', 'KeyA'
'B Key', 'KeyB'
'= Key', 'KeyEquals'
Or you could just create a switch
switch(keyValue)
{
case "A Key": return KeyValue.KeyA;
case "B Key": return KeyVAlue.KeyB;
There are variations on this.
|
|
|
|
|
It’s getting clear now…. Because of my background and my only experience with C# is working with objects, refs and pointers created and generated at run time, I was lost on setting up a reference (linking them) in my code with the instantiation of a pre-existing object dragged onto the Form. Every help link is about creating an object with your definitions and manipulating what you created not syntax/methodology on decoding what you didn’t create.
Thank you………..
And I understand Class and SubClass structure but not how to maneuver around in it in C#.
Now that I can pass my Form Control around in my code I’m not sure the buzz words to comprehend this problem (abbreviated):
private void ManuplateButtons(Control InputButton)
{
InputButton.Text = // Good
Button12.FlatStyle = // Good (pre-instantiated on Form)
InputButton.FlatStyle = // CS1061 'type' does not contain a definition …………
Button FlatStyle is available but Control FlatStyle is not in the list of parameters. So now I need to learn how to dig into the object reference(Control InputButton) to find how FlatStyle is referenced inside of the object reference (Control InputButton).
Is it Control.InputButton.A.B.C nope, so I need to learn how to navigate into the object reference (Control InputButton) and query where FlatStyle is stored or discover what else I can do with an object I didn’t create. I imagine this is not an across the board answer because of the many things you could put/reference in an object.
Timeout; I was composing this when I just read jschell’s post. I believe I have caught up to your post.
In reference to above and #1: I usually depend on the Visual Studio dropdown list and look up the details of the options available until I find the parameter/function that I need or the research of the p/f leads me to an answer. The available button12.X where x = Flatstyle, Flatstyle is in the list but in the case of reference(Control InputButton). Flatstyle is not in the list so I must find it……….. methodology unknown to me ‘yet’.
“…..convert from string to enum” but I need to find the enum def for reference(Control InputButton).Flatstyle before I can convert my string to the relevant enum. I understand the cross correlation between 1 & 2 of jschell’s post.
What are the key search phrases of OOP for the methodology and implementation of how discover what is enumerated in an object that is not shown in the dropdown list, because if “string must match the name of the enum exactly” I need to find the exact spelling or the relevant reference. I know a blind search is going to give me a 1000 hits on how to enumerate a string not how to dig into an unknown enumerated string to find out what is inside, so any tips or pointer links on how to decode an existing object would be useful. Once I learn what is available inside I can learn how to manipulate it…………
Thanks……….
|
|
|
|
|
Button, inherits from ButtonBase, which inherits from Control.
FlatStyle is defined in ButtonBase. At a minimum, you need to "cast" Control to ButtonBase to access that property.
As a side note, ButtonBase is an "abstract" class: you can't actually create ButtonBase except via a class that inherits it (like Button, CheckBox, and RadioButton; or your own "custom" button).
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Thank You Jerry,
ButtonBase BUTTONx = this.Controls.["button1"];
I tried that before and ButtonBase doesn't associate with the string name. I get error CS1001 at the '['.
This doesn't work either ButtonBase.Button BUTTONx = this.Controls.["button1"];
|
|
|
|
|
Codice Fictor wrote: this.Controls.["button1"];
I seriously doubt that there is any situation in which the period before the bracket would ever be valid.
|
|
|
|
|
I posted about "is" and "as" already in this thread; which would have answered your question.
The other aspect related to "is" and "as" is "boxing"; but that is generally used for "value types".
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
i want code to search in data grid view by date that the same date in date time picker tool in the same form ?
|
|
|
|
|
And what help are you expecting from this forum?
|
|
|
|
|
OK, the only code you get is the code YOU write.
Don't search the grid. Search the DataSource your grid should be bound to. If you're not already doing this, you're making it much more difficult on yourself.
|
|
|
|
|
Dave Kreskowiak wrote: OK, the only code you get is the code YOU write. When people ask for code, we now can direct them toward ChatGPT. *evil grin*
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I waded through all the detritus that the AI powered search engines tossed at me, and managed to narrow things down with:
Quote: C# search for date gridview from date picker
https://stackoverflow.com/questions/62045173/filter-datagridview-from-datepicker
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Probably the most relevant part of that link is the following very important advice when searching for time values.
"Because, no matter how hard I tried, I could not remove the time from the datetime value . . . I decided to use a greater than date and less than date."
Although it is still incorrect.
That is exclusive on both ends. One needs to to exclusive on one end and inclusive on the other.
|
|
|
|
|