|
|
Just as all seems clear, something comes along that blows way one's fundemental assumptions about life etc.
How can an object determine the type of object by which it was instanced - essentially who done the new that bought me to life.
I assumed "this" was about the current instance, one of the things that annoys me about "this" it's baggage.
I wanted to know the context in which a particular class member (a set accessor) was being used, and I thought a'ha there must be something in all that "this" baggage that will give me the name of the instancing class - but I can't find it - it seems I can get lots of info about "who" I is, but precious little about "where" I is.
I thought I'd try walking the stack, but I can't find that either, not even 42.InstancingClass works
mad:
Squarks - PhilD
|
|
|
|
|
You probably want to know about reflection. http://my.execpc.com/~gopalan/dotnet/reflection.html .
This is a pointer to the current object. It's not baggage because it is useful for all sorts of function calls referring to the object itself (among other things the compiler must have it for).
"I wanted to know the context in which a particular class member (a set accessor) was being used, and I thought a'ha there must be something in all that "this" baggage that will give me the name of the instancing class - but I can't find it - it seems I can get lots of info about "who" I is, but precious little about "where" I is."
Do you mean you want to know which class was calling this object? That's more difficult, and usually if your using reflection, it means you did something wrong anyways. Try redesigning your code to avoid it.
J
Did I post well? Rate it! Did I post badly? Rate that too!
|
|
|
|
|
Totally agree, a member should not need to know its instancing class - what I have to do is to log events based on the values of the objects properties, the most sensible place to do that is in the object set accessor. In addition to logging the objects properties, I am also required to log the event context, what better way than to include the instancing class tree, the defining class tree is of little consequence in this scenario. And we'd prefer that the instancing classes not know that the objects are being monitored.
The annoying thing is that I can see all the information I want- its in the stack window.
I'll read Gopalan's article - I've been trying to avoid knowing about Reflection, not on principle, but because my brain has a limited learning capacity, on the threshold of which I currently exist.
Thanks for your response - rgds PhilD
|
|
|
|
|
Hi,
you are looking for the StackTrace[^] class. Just create a new instance and will contain all information you need.
Robert
|
|
|
|
|
Thank you robert - I knew it had to be there somewhere MS rarely let developers down
|
|
|
|
|
Why don't you have the instantiating class supply the necessary data to the instance? Unless it's methods that you're after, that if needed to be shared could be in another class and/or static.
this only provides a reference to the current instance of the class. It will only access members of that instance.
Generally speaking, a class holds necessary data, and performs necessary functions based on that data, to represent a finite piece of the problem domain. If you're class doesn't have all the data it needs, you have a design problem. It shouldn't need to look elsewhere for what it needs.
Try code model generation tools at BoneSoft.com.
|
|
|
|
|
I have a struct that I am serializing in C++ so I don't have access to the .Net architecture (and I can't change that). I'm using winsock to transmit it over to a C#. How can I correctly serialise and receive this? All of the serialisation techniques I have seen in .Net are for objects also serialised in .net, or, I'm worried that if I use some sort of binary formatter I am going to get the packing of the struct wrong for my c++ struct.
Suggestions anyone?
Did I post well? Rate it! Did I post badly? Rate that too!
|
|
|
|
|
I am building a touch screen solution. Currently I have 4 forms, one for each piece I am trying to collect. However I have an "Enter your Name" with a textbox and a keypad on the Touch screen.
Form2 frm=new Form2(this.txtFName.Text);
frm.Show();
This is what I am doing for all my forms. Is there a way to keep it on 1 form and just change the controls without having to go to a different form?
Thanks
|
|
|
|
|
Hi,
you could design a Form with your keypad and add a panel to it. Then redesign all your other forms to be user controls instead. Then you can just add/remove those to/from the panel:
private void ShowNextControl(Control control) {
_panel.Clear();
control.Dock = DockStyle.Fill;
_panel.Controls.Add(control);
}
You could also make a base form with the keypad and inherit all other forms from this. The only issue with this is that the Visual Studio designer sometimes shows weird behaviour when working with inherited forms.
|
|
|
|
|
What language are touch screen applications ussualy written in? Should I attempt to write this app in Flash? Is having multiple forms bad software development?
So my base should be the keaboard and the empty space above it would be the actual text boxes. Do inherited forms behave weirldy at run time once the project is developmed?
Thanks for your insight.
|
|
|
|
|
oskardiazdeleon wrote: What language are touch screen applications ussualy written in?
Don't know. Haven't written one yet .
oskardiazdeleon wrote: Is having multiple forms bad software development?
In general not. I've just made a suggestion on how to solve your problem.
oskardiazdeleon wrote: Do inherited forms behave weirldy at run time once the project is developmed?
No its just a designer issue. Once everything is compiled no more weird behaviour. With 'weird' I mean that sometimes the designer moves controls around or is just removing them completely. I haven't found out when this happens but as I do rather complex GUIs at work it happens somehow regulary (probably 1-2 times per month). It seems to be related with the content of the inheriting form...
Robert
|
|
|
|
|
I have a FileBackup application which has a StatusBar and includes 2 StatusBarPanels.
When I minimize the FileBackup window and subsequently maximize it, the StatusBar status stops updating. This also occurs if another window takes focus and then focus is returned to the FileBackup window.
I have tried various things but as yet have not found out how to get the StatusBar to resume displaying updates.
Status messages fire a StatusBarEvent:
private void StatusBarEvent(object sender, FileBackup.StatusEventParams e)
{
if (e.Panel == 1)
{
statusBarPanel1.BeginInit();
statusBarPanel1.Text = e.Text;
statusBarPanel1.EndInit();
}
}
Any ideas?
|
|
|
|
|
|
I was under the impression that doing updates between a BeginInit and EndInit improved performance.
|
|
|
|
|
|
Thank you for the tip, but that doesn't answer my original question of how to get the StatusBar to resume updates.
|
|
|
|
|
I have added a folder and file to the solutions explorer, how do you read and write to that file without specifing the complete file path? If I set a file path inside the program then when it is installed will it still see the file in its new location.
|
|
|
|
|
You simply use relative pathes
eg.
if the file is in the same folder as your exe:
File.Open("MyFile.ext");
if it's in a subfolder:
File.Open("SubFolder\\MyFile.ext");
|
|
|
|
|
At first that is what i had but when i restarted .net it stopped working and i started getting an error that it could not find the file. But after i restarted .net again it works, not sure why it keeps going back and forth. Thanks anyway for the info.
|
|
|
|
|
This is driving me nuts, can some help? I am new to c# but an old hand at C++ and Java.
It is probably very basic but here goes.
http://msdn2.microsoft.com/en-us/system.windows.forms.notifyicon.balloontipclicked.aspx[^]
This is how to use this event but it is not working.
so I add the event handler to the object
this.WSNotifyIcon.BalloonTipClicked += new System.EventHandler(this.WSNotifyIcon_BalloonTipClicked);
(WSNotifyIcon is an instance of NotifyIcon
then I define my event function
public void WSNotifyIcon_BalloonTipClicked(Object sender, uint id)
{
Console.WriteLine("clicked event.");
}
The method is already part of the NotifyIcon class so I should not have to do anything else right?
Thanks
|
|
|
|
|
I believe that will be all you have to do to get it to work. Did you test it?
|
|
|
|
|
You're basically saying, "when the balloon tip is clicked, call the WSNotifyIcon_BalloonTipClicked function. It's of type EventHandler."
The problem lies in the fact that your WSNotifyIcon_BalloonTipClicked doesn't match the EventHandler signature. If you look at the signature of EventHandler delegate, it returns void (you're good there), it takes an object as its first parameter (you're good there) and it takes an EventArgs as its second parameter (oops! yours takes a uint).
Make your WSNotifyIcon_BalloonTipClicked conform to the EventHandler signature. To do that, change the second parameter to be type EventArgs.
p.s. in C# 2, you can omit the "new System.EventHandler(" part. For example, this is valid and more concise syntax:
this.WSNotifyIcon.BalloonTipClicked += this.WSNotifyIcon_BalloonTipClicked;
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Goof around music jam with my brothers (with video)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
I love all the random formatting that is provided, but I'm having an issue with the default percent formatting. I databind a decimal value in a dataset to a textbox, and set the default formatting to "#,##0.##%" The problem is my end-user is slightly annoyed with the resulting format.
If the end user inputs 2.34 (with their interpretation of 2.34%), it formats itself to "234%". If the end-user wants to end up with a display of "2.34%", he needs to entier either that, or .0234.
My question is simply this, is there a way to override the percent formatting, or another custom string taht I can use that won't automatically do the "multiply by 100" in the format?
|
|
|
|
|
I can think of another way to do it, but it's a bit longer:
1- Create the text box.
2- Parse it into a float to validate the input
3- Format the float with your desired format into a string
4- Do whatever you want with that string
The code I used is like this:
float test = float.Parse(textBox1.Text);
MessageBox.Show(test.ToString("#,###.##") + "%");
|
|
|
|