|
If you don't understand how to use two class together then you have a quite a bit more to learn than can be explained here.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
i meant i couldnt complete the logic only for that search and to interact that two classes
|
|
|
|
|
|
I replied to you in the Quick Answers forum. Why are you now asking the same question in a different forum?
This is called cross-posting and is considered rude.
If you did not understand my previous answer then respond to it saying so and saying why.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
This is my code.I was asked to draw a rectangle on the picture box.When i run the program,i can only draw the rectangle on the form but not the picture box.Kindly assist as i am a first timer to C#.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
Boolean bHaveMouse;
Point ptOriginal = new Point();
Point ptLast = new Point();
public void MyMouseDown(Object sender, MouseEventArgs e)
{
bHaveMouse = true;
ptOriginal.X = e.X;
ptOriginal.Y = e.Y;
ptLast.X = -1;
ptLast.Y = -1;
}
private void MyDrawReversibleRectangle(Point p1, Point p2)
{
Rectangle rc = new Rectangle();
p1 = PointToScreen(p1);
p2 = PointToScreen(p2);
if (p1.X < p2.X)
{
rc.X = p1.X;
rc.Width = p2.X - p1.X;
}
else
{
rc.X = p2.X;
rc.Width = p1.X - p2.X;
}
if (p1.Y < p2.Y)
{
rc.Y = p1.Y;
rc.Height = p2.Y - p1.Y;
}
else
{
rc.Y = p2.Y;
rc.Height = p1.Y - p2.Y;
}
ControlPaint.DrawReversibleFrame(rc,
Color.Black, FrameStyle.Thick);
}
public void MyMouseUp(Object sender, MouseEventArgs e)
{
bHaveMouse = false;
ptLast.X = -1;
ptLast.Y = -1;
ptOriginal.X = -1;
ptOriginal.Y = -1;
}
public void MyMouseMove(Object sender, MouseEventArgs e)
{
Point ptCurrent = new Point(e.X, e.Y);
if (bHaveMouse)
{
if (ptLast.X != -1)
{
MyDrawReversibleRectangle(ptOriginal, ptLast);
}
ptLast = ptCurrent;
MyDrawReversibleRectangle(ptOriginal, ptCurrent);
}
}
protected override void OnLoad(System.EventArgs e)
{
MouseDown += new MouseEventHandler(MyMouseDown);
MouseUp += new MouseEventHandler(MyMouseUp);
MouseMove += new MouseEventHandler(MyMouseMove);
bHaveMouse = false;
}
}
}
|
|
|
|
|
Please clarify. When you say you cannot draw the rectangle on the picturebox what happens when you drag within the picturebox? Where is the rectangle drawn?
Also does it have to be a ReversibleFrame or will a normal rectangle do?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
sorry i'm a first timer so please forgive me.
when i drag with the picturebpx to draw a rectangle nothing happen but when i drag it from the form across the picturebox i'm able to draw.
but now i'm asked the draw the rectangle inside the picturebox so this is the problem.
a normal rectangle will do i can do the reversibleFrame myself. thanks
|
|
|
|
|
You need to make your event handlers point to the picture box:
protected override void OnLoad(System.EventArgs e)
{
this.pictureBox1.MouseDown += new MouseEventHandler(MyMouseDown);
this.pictureBox1.MouseUp += new MouseEventHandler(MyMouseUp);
this.pictureBox1.MouseMove += new MouseEventHandler(MyMouseMove);
bHaveMouse = false;
}
Also where you set the points:
private void MyDrawReversibleRectangle(Point p1, Point p2)
{
Rectangle rc = new Rectangle();
p1 = this.pictureBox1.PointToScreen(p1);
p2 = this.pictureBox1.PointToScreen(p2);
.......................
.......................
.......................
.......................
}
When the mouse is up, the rectangle will disappear you therefore need to draw a rectangle using the OnPaint event of your picturebox.
Hope this helps.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
The scope of your mouse event handler is based on the form - that's what you specified when you hooked it up in your OnLoad. Change the scope there to be the picture box and you'll be good to go - to do this, change
MouseDown += new MouseEventHandler(MyMouseDown); to
picDrawing.MouseDown += new MouseEventHandler(MyMouseDown); (Assuming you named your picture box picDrawing).
|
|
|
|
|
I have a program from which I am calling a subordinate form with the axmediaplayer name axWMP.
I want the subordinate form to run from the keyboard but the key strokes are not seen unless I click on the form. It seems that the form loses focus because the keys strokes go to my compiler not the form.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace IRmediacontrol
{
public partial class WMP : Form
{
string fname = "";
public WMP(string filename)
{
InitializeComponent();
fname = filename;
}
private void axWMP_KeyPressEvent(object sender, AxWMPLib._WMPOCXEvents_KeyPressEvent e)
{
label1.Text = "key press = " + e.nKeyAscii.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
axWMP.URL = fname;
axWMP.Ctlcontrols.play();
}
}
}
Any help would be appreciated!
modified on Thursday, October 14, 2010 7:16 PM
|
|
|
|
|
Just add
axWMP.Focus(); after you make the .play() call.
|
|
|
|
|
I had tried that prior to the .Play call and it didn't work. Your suggestion solved the problem.
Many Thanks.
|
|
|
|
|
Please mark his answer as the right answer (by clicking on the Good Answer link).
|
|
|
|
|
|
I'm afraid I still have the problem. I thought that the problem had been solved as clicking on the button caused the key commands to work. In actuality clicking the button was bringing the focus to the form. Here is the code with no button which loses focus.
public WMP(string filename)
{
InitializeComponent();
this.axWMP.KeyPressEvent += new AxWMPLib._WMPOCXEvents_KeyPressEventHandler(this.axWMP_KeyPressEvent);
fname = filename;
axWMP.settings.autoStart = false;
axWMP.URL = fname;
axWMP.Ctlcontrols.play();
axWMP.Focus();
}
private void axWMP_KeyPressEvent(object sender, AxWMPLib._WMPOCXEvents_KeyPressEvent e)
{
label1.Text = "key press = " + e.nKeyAscii.ToString();
}
|
|
|
|
|
I see what you want now, and no, the .Focus() won't do the trick.
My question is whether you are trying to capture keystrokes in a generic manner and then pass on the relevant ones to the child form?
The issues may lie with where the focus lies. The keypress arguments are going to be sent from whichever control has the focus, not the form itself, so you won't see the event using the hooks you have. What you need to do is capture the keypress event from whichever control happens to have the focus on the active form and then pass the keystroke event down to the sub form for it to use it. If you tell me which version of Studio you're using, I can package up a sample I just made to demonstrate this and send it to you. You can email me that at [edited out now that you've gotten it], if you like.
modified on Thursday, October 14, 2010 8:50 PM
|
|
|
|
|
If I click on the form all works as it should. I am writing a mediaplayer that functions from a IRremote so I dont want to have to click on the form with a mouse in order to read the key commands.
|
|
|
|
|
PogoboyMtK wrote: You can email me that at
If you want to do that again, there is an Email button at the bottom of your message which means you don't have to expose your email address to Googles' page cache at all.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Thanks. It's ok though, because I expose my "utility" email address and not my primary one.
|
|
|
|
|
Handling the problem by e-mail keeps other interested parties from seeing the solution to a problem. If it is too much for a forum post, you might consider writing a tip&trick or even an article about it.
|
|
|
|
|
Your right. I finally found the answer to the problem. The child form was not the problem. In the parent form I had done this:
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
Form2 dlg = new Form2(fname);
dlg.ShowDialog();
For some reason this causes Form2 to be inactive I know not why.
|
|
|
|
|
The main form represents the entire app (when it closes, the app exits). I'm surprised the dialog was even showing, if you had minimized the main form later on, the dialog would have disappeared too (try right-clicking minimize on the task bar on any app).
BTW: these special things you just showed should have been mentioned earlier...
Cheers.
|
|
|
|
|
Agreed. I didn't even think to ask that yesterday.
|
|
|
|
|
Hey Luc,
Rather than span the forum with numerous posts along the way, the idea was to figure out what was wrong and then post that, not the entire process of getting there.
Cheers
|
|
|
|
|
Have you considered using the ProcessCmdKey overload or event ??? instead of keypress event
With great code, comes great complexity, so keep it simple stupid...
|
|
|
|