|
Handle the scroll event of control 1, and in it, set the scroll pos of control 2.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hello,
As the TreeView has no "Scroll" event you would have to inherit your own TreeView.
There you have to set up your own Scroll event with the use of the overriden "WndProc" method.
This [^] nice article shows how to do it!
All the best,
Martin
|
|
|
|
|
how can i change cultur between control?
i have two textbox on form first text write arabic and second textbox write english
123
|
|
|
|
|
how can i change cultur between control?
example , i have two textbox on form first text write arabic and second textbox write english
123
|
|
|
|
|
public abstract class Test_setting_date_value_base : My_test_base
{
[Step ("2.INHERITED attribute")]
protected abstract bool s2_custom (object data);
protected abstract bool s7_custom (object data);
protected bool s7_goto_datetime_month_value_and_press_ok_up (object data)
{//do something
}
public override BlaTests.Test_step [] get_steps ()
{
Test_step [] steps =
{
s1_initialise,
s2_custom,
//...
s7_custom,
s12_deactivate
};
return (steps);
}
}
public class Test_setting_date_value_1 : Test_setting_date_value_base
{
protected override bool s2_custom (object data)
{
return set_date (30, 11, 2003);
}
protected override bool s7_custom (object data)
{
return s7_goto_datetime_month_value_and_press_ok_up (data);
}
}
Is it possible to do for a class the function that overrides previous implementation by setting 'pointer to function' like in JavaScript? I.e. I want something like that in second class (Test_setting_date_value_1):
protected new bool s7_custom = s7_goto_datetime_month_value_and_press_ok_up ;
I dont' know, but it somehow connected to keyword delegate.
-- modified at 5:14 Thursday 15th November, 2007
|
|
|
|
|
I mean I want that:
Parent has abstract and ordinary method.
Child overloads abstract method with parent's ordinary second method.
So its like I want to assign to abstract method already existant parent's method (or child's method) in the way something like that:
protected bool s7_custom = s7_goto_datetime_month_value_and_press_ok_up ;
//s7_custom - abstract
//s7_goto_datetime_month_value_and_press_ok_up - already defined in parent (or child)
So if s7_custom() called, then s7_goto_datetime_month_value_and_press_ok_up() is called instead.
|
|
|
|
|
Hi all,
Is there a way that I can choose which property of a control to set and then set it, all at runtime?
Let's say I want to set the text on a button at runtime to a string value I read from a file, that's easy. I simply call:
myButton.Text = strMyVal;
The same goes for setting the size, the location or whatever.
However, what if I will only know at runtime which property needs to be set. So I have two variables, strPropertyName and strPropertyValue . How do I set the property of myButton that matches strPropertyName to strPropertyValue ?
I was hoping for something like:
myButton.PropertyByName(strPropertyName) = strPropertyValue;
but to my knowledge there is no such thing as a PropertyByName method.
Any other ideas?
|
|
|
|
|
Hello,
The answere to your problem is "System.Reflection"!
PropertyInfo actPI = yourControl.GetType().GetProperty(yourPropertyName);
if(actPI!=null)
actPI.SetValue(yourControl,yourPropertyValue,new object[0]);
Hope it helps!
All the best,
Martin
|
|
|
|
|
Aaah, sweet! Thanks man. I just love when some comes out with such a quick and straightforward answer that does EXACTLY what I've been looking for.
|
|
|
|
|
Glad I could help!
You are wellcome!
All the best,
Martin
|
|
|
|
|
Martin#, I'm going to push my luck and ask a related question. I'm sure that the answer also lies in reflection somewhere but seeing as it's all new to me and will involve some study I thought I'd see if you could help me.
Would there be a way perhaps of instantiating a new object based on a type that is also obtained during runtime? In other words, I read a file which contains XML (or whatever text based representation of objects) which I then would like to put onto a form.
Let's assume the file holds something like:
Type=Button
Name=MyNewButton
Text=My New Button
Now I can read these into variables, let's call them newType, newName and newText.
How do I instantiate a new object? Again Button newButton = new Button() is easy enough but at runtime it could be Label , TextBox or anything else.
After this is over I promise to make an effort of getting on top of reflection.;)
Thanks,
D
|
|
|
|
|
HEllo,
Also here "System.Reflection" helps you.
string knownAssemblyName = ???;
Assembly asm = Assembly.LoadWithPartialName(knownAssemblyName);
Assembly asm = Assembly.GetExecutingAssembly();
string typeStringOfControl = ???
Type ctrltype = asm.GetType(typeStringOfControl);
ConstructorInfo ci = ctrltype.GetConstructor(Type.EmptyTypes);
object ctrlInstance = ci.Invoke(new object[0]);
All the best,
Martin
|
|
|
|
|
Hi Martin,
Thanks, I really apreciate your help. This method seems to work well, for the most part...
The one problem I have is that ctrlInstance is still of type object even though the Button constructor (or whichever type) is used to instantiate it.
The result is that I can't access any properties that are particular to a specific type directly. For a Button I would like to add an event handler for instance but
ctrlInstance.Click += new System.EventHandler(this.ElementHandler);
wouldn't compile because 'object' does not contain a definition for 'Click'
I was hoping that I could then rather to the following:
PropertyInfo actPI = myControl.GetType().GetProperty("Click");
if (actPI != null)
actPI.SetValue(myControl, new System.EventHandler(this.ElementHandler), new object[0]);
Although this compiles (obviously), it doesn't work because actPI is null .
I hope I'm not getting too tedious with my questions but I appreciate your help.
Dewald
|
|
|
|
|
Hello Again,
Dewald wrote: I hope I'm not getting too tedious with my questions but I appreciate your help.
No way!
This is a very interesting discusion, thanks for that!
Now to your problem:
Reflection in combination with delegates is something I have never done.
So I can only give you a maybe dirty solution (but maybe also the only one possible).
I would cast to the object to the appropriate type and then do your stuff.
...
Button actButton = ctrlInstance as Button;
if(actButton!=null)
{
actButton.Click+=...
}
If you have more than one type to validate for some other action with Label, CheckBox, ...
if(ctrlInstance is Button)
{
Button actButton = ctrlInstance as Button;
actButton.Click+=...
}
else if(ctrlInstance is Label)
{
Label actLabel = ctrlInstance as Label;
}
...
Hope that someone will come up with a cleaner solution,
but maybe it fitts your needs.
All the best,
Martin
|
|
|
|
|
Martin,
I thought of following that approach so if you don't have a more elegant sollution then I suppose I'll just use it. It works fine though but, as you said, it's just not as pretty.
If I may, I'd like to return to the original question quickly. You showed me how to use reflection to instantiate an object of any type and then with the SetValue method of PropertyInfo I can set the value of a property programatically.
I just discovered that, while it works perfectly for properties that have string values, it won't work for property that have a value of some funny type. Take Button.Size for instance, if I have
PropertyInfo actPI = myControl.GetType().GetProperty(myPropertyName);
if (actPI != null)
actPI.SetValue(myControl, myPropertyValue, new object[0]);
with myPropertyName = "Size" and myPropertyValue = "75,24" then obviously I'm going to get into trouble.
I could've used actPI.SetValue(myControl, new Size(100, 24), new object[0]); but I will only know at runtime that the property I'm trying to change is Size and I have to store the value in a file (or DB) in some string representation.
Is there an easy workaround for this?
Cheers,
Dewald
|
|
|
|
|
Hello,
Now it looks like you really should look into "Serialization".
In combination with XML it is well supported in .NET, and there are tonns of articels about that.
Like:
this CP article[^]
or look at google![^]
Hope it helps you!
All the best,
Martin
|
|
|
|
|
Hi Martin,
Yes, I think you're correct. I think I will take it upon me to study Reflection and Serialization this weekend.
Thanks again you've been of fantastic help.
Cheers,
Dewald
|
|
|
|
|
You are allways wellcome!
All the best,
Martin
|
|
|
|
|
Hi
I m getting a problem while executing my program. Actually I m trying to send video file from server to client using BufferedStream with TCP. When I debug it,program runs fine and exact video is recieved on the client side. But when I run prog. normally(without Debugging),I get Corrupted video.I m not getting a clue on how this file corrupts when I run normally as this doesn't happen While I debug.
PLZZZZZZZZZ TELL ME ASAP WHAT IS THIS ERROR AND HOW TO RESOLVE IT.
Regards,
Shanzay
|
|
|
|
|
Hi,
Read the file till end into the buffer, and then try sending it.
Regards,
Adeel
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.
|
|
|
|
|
I m sending through streaming by using 16KB buffer as:
byte buf = new byte[16384];<br />
FileStream inStream = File.OpenRead(dlgOpen.FileName); BufferedStream bufInStream = new BufferedStream(inStream);<br />
int bytesRead;<br />
<br />
while ((bytesRead = bufInStream.Read( buf, 0, 16384)) > 0)<br />
sock.Send(buf,buf.Length,SocketFlags.None); <br />
/////////////////////////////////////
At Recieving Side
<br />
FileStream outStream;<br />
outStream=File.OpenWrite(filepath);<br />
rcvfilebuf=new byte[16384];<br />
while(true)<br />
{<br />
socket.Receive(rcvfilebuf);<br />
<br />
bufOutStream = new BufferedStream(outStream);<br />
bufOutStream.Write(rcvfilebuf, 0, rcvfilebuf.Length);<br />
}<br />
This code is doing well while debugging but not in normal running of application.
Shanzay
|
|
|
|
|
Hi,
Tried without reading in buffers?
Reading the whole file in one I/O operation, and then sending it might solve the issue.
Regards,
Adeel
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.
|
|
|
|
|
The problem is at the receiving end, your file is too large.
What will the value be of rcvfilebuf.Length?
Doesn't Socket.Receive return something?
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Yah it returns and its size is 16KB.And I've solved this problem by using thread.sleep(30) before send() from server side but now the file which I m getting at client side the frames of that video file are overlapping so what to do in this case as if File size 10MB then it gives required output but if larger than 20MB then frames becomes overlap in video.
So PLZ SUGGEST NOW How to solve this
Thanx
Shanzay
|
|
|
|
|
DeepOceans wrote: Yah it returns and its size is 16KB
I don't think so.
If the sender's file size is a multiple of 16KB, then all buffers will contain 16KB.
If the sender's file size is not a multiple of 16KB, the last buffer sent will contain
less, but the receiver, the way you did it, will still store 16KB, i.e. the buffer will
contain some older data and write that to the file too. That's what my previous reply
was about.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|