|
#1. Lets say there are two forms (form1, form2) in your application. you put one button called button1 in form2. You wanna get the control (button1) of form2 from form1.
Add one public property which is returned the control that you required in form2
eg:
<br />
public Button Button1<br />
{<br />
get<br />
{<br />
return button1;<br />
}<br />
}<br />
Then, you can access this control from form1.
eg:
<br />
Form2 obj = new Form2();<br />
MessageBox.Show(obj.Button1.Text);<br />
There are another way to get the control from other form or assembles. I'm not gonna mention here. If you are interest about this, please "Reflection" class from MSDN or google.
Hope it helps.
|
|
|
|
|
Thank You
It Helps Me solve My problem
Regard,
Tomi
|
|
|
|
|
You've got an answer already, but I'm asking myself why you want to do this? because I think there is a bit of a design problem here (information hiding? encapsulation?)
-^-^-^-^-^-
no risk no funk
|
|
|
|
|
I have to write the event handler for MSCOMM.OnComm who is listening to serial port for data, so that the event is fired 'OnComm' is executed when the data is arrived.
My understanding for the documentation is unclear as how to achieve this.
Does any one have the sample source code implementation in C# / C++?
Thanks and Regards.
Amar.
|
|
|
|
|
If you're using .NET 2.0 (Visual Studio 2005), why are you even bothering with the MSCOMM control? There's a SerialPort class built into the .NET Framework under the System.Io.Ports namespace.
|
|
|
|
|
Hello,
Trying to write an app that I can work with dual monitors and Windows windows...
I'd like to add buttons next to the minimize button for all windows within Windows. Can anyone point me in the right direction on this?
Thanks!
Andy
|
|
|
|
|
This peace of code will draw a button on title bar , however i don't like to write C# code
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM.NCPAINT Then
Me.DefWndProc(m)
Dim G As Graphics = Graphics.FromHdcInternal(GetWindowDC(Me.Handle))
Windows.Forms.ButtonRenderer.DrawButton(G, New Rectangle(Me.Width - 100, 5, 20, 20), VisualStyles.PushButtonState.Normal)
Else
MyBase.WndProc(m)
End If
End Sub
Other APIs you may use : GetSystemMetrics , GetWindowLong(HWND , GWL_STYLE) , GetWindowInfo -> to determine the size of window's border , to count title button ...
|
|
|
|
|
I want to display the properties of (.swf , .fla) files as height, width and resolution.
|
|
|
|
|
Hi,
Here's the code:
foreach (DataRow dr in myWebLoggerDataSet.MonitorList.Rows)
{
string name = dr["Name"].ToString();
string size = dr["FileSize"].ToString();
string colour = dr["Colour"].ToString();
string display = name +" : " +size;
string[] myItems = new string[]
{
display
};
ListViewItem lvi = new ListViewItem(myItems);
lvi.BackColor = Color.FromArgb(Convert.ToInt32(colour));
this.lvResourceMonitor.Items.Add(lvi);
}
The problem I have is that the item background color is used when debugging in W2K3 server but not when running normally on a Win XP machine. I need to manually select each item in XP to get the highlight color to take effect.
I've tried various options like redraw, giving the listview focus etc but to no effect.
Any suggestions for fixing this very frustrating issue?
Thanks.
-- modified at 5:42 Saturday 14th July, 2007
It happens on W2K3 as well. Works fine in debug mode though.
Glen Harvy
|
|
|
|
|
Hey Glen,
I can't get the same behaviour on my machine... it just works as expected when I try.
Have you suspended any of the drawing methods on the control to improve performance or anything like that? Have you got any other code setting properties on the listview? Have you tried invalidating the form?
|
|
|
|
|
Thanks for you response. I really need someone to talk to - I'm going nuts.
I haven't done anything that I can tell would make the listview behave differently between when run in debug mode versus production mode.
I have also tried lv.refresh, lv.update lv.invalidate various lv.focus etc but all to no efect. I have discovered at least three different ways to change the background color that all work in debug but not production mode.
This is the only instance of this error that I have had so I find it difficult to believe it's my computer at fault.
Could you try this for me please - set the listview to "Details" and see if that makes a difference.
Thanks.
Glen Harvy
|
|
|
|
|
I've just tried all the possible modes, and it they all work like they should - with no need to invalidate, refresh or whatever.
Here's an idea, just so you can see if it works outside of your current project. Create a new WinForms project and put a button and a listview on the form.
In the list view manually add three columns - the names don't matter very much Col1, Col2, Col3 should be fine. Also, switch the grid to details mode.
Place this code in button1's click event:
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
for (int g = 0; g < 10; g++)<br />
{<br />
string[] namesArray = new string[3] { "Martin", "Was", "Here" };<br />
<br />
for (int i = 0; i < namesArray.Length; i++)<br />
{<br />
ListViewItem lvi = new ListViewItem(namesArray[0]);<br />
lvi.SubItems.Add(namesArray[1]);<br />
lvi.SubItems.Add(namesArray[2]);<br />
<br />
lvi.BackColor = Color.FromArgb(Convert.ToInt32("58996"));<br />
listView1.Items.Add(lvi);<br />
}<br />
} <br />
}<br />
When you run the program (I've done it from both Debug and Release folders), hopefully you'll get something like this?
http://img261.imageshack.us/img261/4448/listviewin4.jpg[^]
|
|
|
|
|
I thank you for your time and effort - the fact that it worked for you got me thinking. So this is what I did:
1. Created a new project2 and copied most of the code from project1 in question to a new listview. Everything worked fine so that eliminated my computer. Must be the code somewhere.
2. Went back to my original project1 and commented out the foreach .. loop and copied the code from project2 and it still didn't work.
3. The code worked on project2 - so why not project1.
4. Quadruple checked all the configuration of the two listviews in 1 and 2. I swear they were the same.
5. OK. Create new listview in project1 alongside of the original and used the same code as in project2. - New listview worked. Old listview no good - new listview OK.
6. Used new code (modified) to fill new listview from the table. New listview still works fine with new data.
7. Dragged old listview to vacant part of screen and moved new listview to old listview position. In this action I did something that created an event on new listview. No worries - just deleted the event from the new listview.
8. Now BOTH listviews are working as they should be.
I'll swear I didn't change anything on the old listview.
It's 1:05 am here so I'm going to bed. I am going to get a copy of the backup code tomorrow and compare the two designer code sections - there's gotta be something in there that caused this.
There is one other thing. The new listview was outside of a group box but having "swaped" the two listviews, the problem has not returned.
For the record - here's the code that now works for BOTH listviews:
int i = 0;
foreach (DataRow dr in myWebLoggerDataSet.MonitorList.Rows)
{
string name = dr["Name"].ToString();
string size = dr["FileSize"].ToString();
string colour = dr["Colour"].ToString();
string display = name + " : " + size;
string[] myItems = new string[]
{
display
};
string test = "Bozo";
//ListViewItem lvi = new ListViewItem(myItems); //,0,Color.Black, Color.Pink,Font);
////lvi.UseItemStyleForSubItems = true;
////lvi.BackColor = Color.FromArgb(Convert.ToInt32(colour));
//this.lvResourceMonitor.Items.Add(lvi);
//lvi.BackColor = Color.FromArgb(Convert.ToInt32(colour));
//lvResourceMonitor.Refresh();
this.lvResourceMonitor.Items.Add(display);
this.lvResourceMonitor.Items[i].BackColor = Color.Chartreuse;
this.lvResourceMonitor.Refresh();
lv1.Items.Add(display);
lv1.Items[i].BackColor = Color.FromArgb(Convert.ToInt32(colour));
lv1.Refresh();
i++;
}
The ListviewItem array lvi was not the cause of the problem as far as I can tell. I'm pretty sure of this because I used the new code to fill the old listview without success.
I'm off to bed - once again - thanks for helping me.
Regards,
Glen Harvy
|
|
|
|
|
No problem - things like that frustrate the hell out of me when they happen, so it's good to lend at least a sympathetic ear when it happens to others!
Cheers,
Martin.
|
|
|
|
|
Hi everybody,
I'm currently designing a GUI hierarchy comparable to the Winforms one in XNA, so I have something like this:
class Control
class Form : Control
class Button : Control
and methods like this (that's how .NET does it, I copied it for my own GUI):
protected virtual void OnMouseDown(MouseEventArgs e)
{
mouseDown = true;
}
protected virtual void OnMouseUp(MouseEventArgs e)
{
mouseDown = false;
}
Now I have a controller which traverses the z-order and notifies the control in question that it just got a MouseDown or MouseUp event.
It looks like that:
List<Control> controls = new List<Control>();
void MouseInput_MouseUp(MouseEventArgs e)
{
for (int i = controls.Count - 1; i >= 0; i--)
controls[i].OnMouseUp(e);
}
But I can't call OnMouseUp because it is protected, so how do I tell the control?
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi,
the way I understood it, keyboard and mouse input basically go to the app, Application.Run(new Form1()) make them go to your instance of Form1, and from there they get dispatched
to the Form and its content (thru Controls property).
BTW: there is a free implementation of .NET available under ssCLI or shared source CLI.
Google will locate it for yoi.
Hope this helps.
|
|
|
|
|
Luc Pattyn wrote: the way I understood it, keyboard and mouse input basically go to the app, Application.Run(new Form1()) make them go to your instance of Form1, and from there they get dispatched to the Form and its content (thru Controls property).
Do you have any source where this behaviour is described?
Luc Pattyn wrote: BTW: there is a free implementation of .NET available under ssCLI or shared source CLI.
You mean Mono? I will check out their source. I'd still love some explanation what's really on with those OnXXXMethods
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
|
Thanks, I will take a look at it
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
This is probably off-topic in that it doesn't relate directly to C#, but I'm hoping for some leeway...
I've done a lot of audio programming using both C# and C++. With both MDX (Managed DirectX) and the Win32 multimedia library, you can choose which device on your system to send waveform data to. For example, if you have several soundcards installed, you can choose which one plays your sounds.
I need to know the equivalent for video, i.e. I need to know what API I can use, hopefully with C#, that will allow me to choose from several video devices installed to send my video output to. MDX lets you play video files but they must be displayed in a window; there's no functionality, as far as I can see, to choose from various devices.
Any help is appreciated.
|
|
|
|
|
i need help on how 2 dimensional-discrete wavelet transform works for images because i have a class in 1 dimensional form
|
|
|
|
|
Good luck. Did something like that in a Master's course a few years ago. Do you have a specific question?
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
I see many programs do this, they read the screen using bitmap and screencapture and interpret the results. I got the code to capture screen using C#, and have converted to bitmap, but the only usable method is getPixel(int x, int y). For example here is some of my code:
Bitmap bt = (Bitmap)image1; //assume image1 is the screen capture output
String p = bt.getPixel(50, 100).toString(); which returns a string containing some information in RGB format,
now I do a if statement:
if(p == "some reference RGB")
return true;
else
return false;
Now as you can see this method takes a long time to first capture screen, convert to bitmap, read pixel of bitmap, compare it to reference, and return boolean. I was wondering if there was an easier way using API methods of the GDI32 dll file, that makes this easier and faster or whether its always slow.
How do "auto" programs work? I would like some information if anyone can help me please.
My source is always free, so support my applications.
MAx.
|
|
|
|
|
Try using unsafe code to scan the bitmap.
There's a series of articls about image processing, written by Christian Graus, here in CodeProject.
You can find the first one here[^].
Regards,
Shy.
|
|
|
|
|
Hello experts,
It is well known that when a string's length is already known or can be easily calculated, it is best to use StringBuilder instead of string .
But... How should one go about handling the following situation:
string alreadyAllocated = "ABCD";
string newString = "BLABLA" + alreadyAllocated; The way I see it, it's the same as doing:
string alreadyAllocated = "ABCD";
newString.Append("BLABLA");
newString.Append(alreadyAllocated); The reason I think it's the same is because to my understanding, when hardcoding the "BLABLA" string, memory is allocated for it anyway.
So the resulting pseudo code in both cases would be something like:
- Allocate memory for "BLABLA"
- Allocate memory for "BLABLA" + alreadyAllocated
- Copy both allocated strings to the new large location
Care to share your knowledge and opinions?
Thanks in advance,
Shy.
|
|
|
|