|
Maybe I misunderstood the question, but you already have the property name (targetObject.X). Why do you need it again?
BTW, you can also achieve the same effect by creating a delegate to PropertyInfo.SetValue[^]. The code would then look like
class Test
{
int x;
public int X
{
get {return x;}
set {x = value; }
}
}
delegate void XDelegate(object obj, object value, object[]index);
static void Main(string[] args)
{
Test t = new Test();
PropertyInfo propertyInfo = t.GetType().GetProperty("X");
XDelegate xdel = new XDelegate(propertyInfo.SetValue);
xdel(t, 2, null);
Console.WriteLine(t.X);
}
|
|
|
|
|
S. Senthil Kumar wrote: Maybe I misunderstood the question, but you already have the property name (targetObject.X). Why do you need it again?
The issue with entering it into the code as a string is that typos aren't detected until runtime. This has burned me severa; times already.
Thanks for the delegate example. The only one I was able to find left the impression that it only would work with classes that supported the Invoke method, which mine did not.
|
|
|
|
|
dan neely wrote: The issue with entering it into the code as a string is that typos aren't detected until runtime.
A very valid concern, but that's the cost of using reflection and runtime method invocation, I guess. You have to make assumptions that cannot be verified at compile time. Instead of hardcoding a string, you could, for example, get all properties on a class and access the nth property, but that assumes new properties are always added at the end.
|
|
|
|
|
.NET newbie question
I have a Collection object that I would like to copy into another collection object.
The collection is of type:
System.Collections.ObjectModel.Collection<System.Windows.Controls.ValidationRule>
The Collection.CopyTo method requires that I provide an array and an index. The question is: How do I syntactically express the array portion of the target collection.
I can't do this, because param 1 is a Collection:
Collection1.CopyTo(Collection2, 0)
I hoped I could do something like this to specify the array, but alas no:
Collection1.CopyTo(Collection2[], 0)
Is there a way I can do this or do I have to enumerate the contents of Collection1 and Add to Collection2?
Thanks
|
|
|
|
|
Well, you could always do
Collection2.Clear();
Collection2.AddRange(Collection1);
|
|
|
|
|
No such method (AddRange) on the Collection class.
|
|
|
|
|
My bad. I assumed you were using the List class. Looks like you have no other option other than looping over and copying elements.
|
|
|
|
|
Such is life in .NET.
Times like this I miss things like memcpy and void **
~
|
|
|
|
|
I have a windows control that I need to show in a web browser. I know that you can load a control in a browser using this method:
<br />
<object id="MyControl" classid="MyControl.dll#MyNameSpace.MyControl"><br />
</object><br />
However, the control I need to show, isn't very small and I noticed that the clients machine doesn't save a copy of the control on their computer (only as a temp file). I would like the control to act like an ActiveX where the control gets downloaded on the clients machine once, and not everytime the user browses to site.
I have also tried exposing the control for COM and tried (as you can see, I compressed the control in a CAB file):
<br />
<OBJECT CLASSID="clsid:1A41BBAF-9059-37AF-BCEF-CC8BB318D4CC"<br />
CODEBASE="MyControl.cab#version=1,0,0,0" ID="MyControl" ><br />
</OBJECT><br />
Using this method the control gets downloaded to the clients machine, it is still a .NET assembly it doesn't get registered on the client machine, and thus doesn't get envoked.
Does anyone have any ideas, or am I missing something?
Thanks in advance
Jeremy
|
|
|
|
|
Hello,
I have a problem, my application is drawing a simple text in the middle of a window, but the text is rotated by a user-defined angle. The problem is I cant make the text appear in the middle (the rotating makes the point change its location. My code looks like follows:
<br />
graphics.RotateTransform(-rotateAngle);<br />
graphics.DrawString(mystring, myfont, myBrush, drawpoint, new StringFormat());<br />
I know I should put a graphics.TransformTranslate(_x,_y) - BUT I HAVE NO IDEA HOW TO FIGURE OUT THE POINTS for that purpose (before the locatin I was simply using X=width/2-measurestring/2, Y=height/2-measurestring/2). Any one know the maths for that ?
|
|
|
|
|
You need to do a TranslateTransform to change the point of rotation.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Sorry - I see you know to translate - use Graphics.MeasureString to get the size of the string you want to draw.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
well, I actually use the MeasureString and TranslateTransform, but the problem is that Im drawing the string in that way
- Rotate the graphics by an user-specified angle
- Draw text
- Rotate the graphics back to the previous position
After this three steps I got an imaged and a text drawn on it on an angle I specified. The only problem is that I want to draw the text lets say in the middle and Im not sure how to get the coordinates of the point that after the rotating back the text will be at the middle of the image.
Its actually a math matter, but Im not sure how to solve it.
|
|
|
|
|
seq- wrote: - Rotate the graphics by an user-specified angle
- Draw text
- Rotate the graphics back to the previous position
Where are you using the Translate ?
You need to move the image so that 0,0 is the centre of the point of rotation you want to achieve.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
So, I have a vendor application that, among other things, uploads some very large files from a portable hard drive to my network storage server. This takes anywhere from 5 minutes to an hour, so I'm trying to write a helper app to automate the process so my users can start this vendor-provided upload program and walk away from the PC, and my helper app will do the rest. Essentially, I'm writing one app to control another app. (Rewriting or not using the vendor app is not an option.)
When the file(s) upload is complete, the vendor app pops up a message box saying "Upload Complete" and waits for the user to click OK before proceeding with other tasks. I need some way for my app to detect when this message box event occurs as that's the cue for my app to start another process and finish up the file processing tasks.
Or, I need to run a timer and check every minute or so to check for the presence of the message box, if that's a better way.
Or perhaps I can monitor the file upload and when it stops, go from there... I'm not exactly overflowing with good ideas about how to do this, and I'm open to any ideas/suggestion.
Any help is greatly appreciated. If you are going to suggest using Win32 hooks, detail is appreciated as I don't understand much about using them.
Theo
|
|
|
|
|
Hi All
I need to write some application ( client \ server ) that can connect to some remote computer ( by TCP\IP ) and show the user the screen ( what the other user of the other computer see ) of this machine.
What i don't know is if there is some method in C# that can help me with this.
What i need is some method that can return me some screen shot or some bit stream
that in the server i could collect this bit stream and show the screen of the remote machine.
Thanks for any help.
|
|
|
|
|
Have you looked at VNC? I know it's not quite what you're after, but depending upon your required application it may be an option.
ChrisB
|
|
|
|
|
that already work.
VNC is not open source.
|
|
|
|
|
Yanshof wrote: VNC is not open source.
Tight VNC is OSS. It's not the most efficent implementation outthere but it works.
http://sourceforge.net/projects/vnc-tight
|
|
|
|
|
You may also want to look at fogcreek copilot[^]which is a commercial project built upon the tightvnc core.
ChrisB
|
|
|
|
|
I have a large treeview I need to build and it takes about 1 minute to load. what I'd like to do is load the treeview in background. I tried doing it through, but it causes the main form to freeze until it's complete. Does anyone know what the best process is to load things in the background not affecting the main application screen.
Thanks.
|
|
|
|
|
Hi
Use System.Threading to Perform your request (Loading Treeview)
Good Luck
|
|
|
|
|
Or even easier (if you're using .NET 2.0) is to drop a BackgroundWorker process onto the form. It's DoWork event will fire a method on the form where you can do your processing.
Be warned however, that Windows Forms aren't thread safe, so any manipulation of the form controls requires jumping back onto the main thread using Control.Invoke or Control.BeginInvoke to call a delegate. Eg.
<br />
public partial class MyForm<br />
{<br />
delegate void AddItemDelegate(string text);<br />
<br />
private void AddItem(string text)<br />
{<br />
if (InvokeRequired)<br />
{<br />
BeginInvoke(new AddItemDelegate(AddItem), new object[] { text });<br />
return;<br />
}<br />
myListBox.Items.Add(text);<br />
}<br />
<br />
private void myListBox_DoWork(object sender, DoWorkEventArgs e)<br />
{<br />
foreach( string item in myList )<br />
{<br />
AddItem(item);<br />
}<br />
}<br />
}<br />
|
|
|
|
|
Hi,
I have a dialog box where the user can edit some fields. I need to display an error message if some fields have wrong data when the user clicks OK, and I'd like to keep the dialog open, so they can change those fields.
How can I do that?
thanx
|
|
|
|
|
I'm assuming that you're using ShowDialog() to show the form and have set the ok button to give a DialogResult.OK. In which case, remove the dialogresult from the ok button, execute code to check and display error message. If no error message is displayed, set the form.DialogResult = DialogResult.Ok in code. Then close the form.
ChrisB
|
|
|
|