|
ok well by firing i mean you are going to have the following line of code
this.uxBtnCreateOrder.Click += new System.EventHandler(this.CreateOrder_Click);
Now I am quite weak in custom events but isn't this where you decide to where the event will go? So I can't figure out how to send this to the parent.
|
|
|
|
|
That's done by the parent, not the child.
child.SomeEvent += new System.EventHandler ( this.SomeHandler ) ;
|
|
|
|
|
The child form can access it's parent by its MDIParent property. The downside of this is it is of type Form rather than the actual class that you have created so you can't access any custom properties or methods.
The best way, is for the Child to raise events. The parent can subscribe to them immediately after it has instanciated the child. Very simple example below.
using System;
using System.Windows.Forms;
public partial class FormParent : Form
{
public FormParent()
{
InitializeComponent();
IsMdiContainer = true;
FormChild frmChild = new FormChild();
frmChild.MdiParent = this;
frmChild.ChildEvent += new EventHandler<ChildEventArgs>(frmChild_ChildEvent);
frmChild.Show();
}
void frmChild_ChildEvent(object sender, ChildEventArgs e)
{
MessageBox.Show(e.Message);
}
}
using System;
using System.Windows.Forms;
public partial class FormChild : Form
{
public event EventHandler<ChildEventArgs> ChildEvent;
public FormChild()
{
InitializeComponent();
Shown += new EventHandler(FormChild_Shown);
}
void FormChild_Shown(object sender, EventArgs e)
{
PerformChildEvent();
}
void PerformChildEvent()
{
OnChildEvent(new ChildEventArgs("Child Event"));
}
protected virtual void OnChildEvent(ChildEventArgs e)
{
EventHandler<ChildEventArgs> eh = ChildEvent;
if (eh != null)
eh(this, e);
}
}
public class ChildEventArgs : EventArgs
{
private string m_Message;
public ChildEventArgs(string message)
{
m_Message = message;
}
public string Message
{
get { return m_Message; }
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
actually so what you are saying is that you shouldn't try to directly handle the form event on the parent, but rather you should handle the form event on the child form and in that event handler fire a custom event and that event you can handle on the parent form?
|
|
|
|
|
Sort of!
Anything that happens in the Child that the Parent (or anyone else) may be interested in should be handled by the Child raising an event that the Parent can subscribe to.
If there's already an appropriate event, then simply raise that by calling the OnXxx method for that event (it should also be overrideable if you need to do more with it and then call the base method). If not, create a custom event and raise that.
By the way, I included the customized event args for illustration, but if no data is needed to be passed, then you can declare the event as...
public event EventHandler ChildEvent;
and the raising becomes...
void PerformChildEvent()
{
OnChildEvent(EventArgs.Empty);
}
protected virtual void OnChildEvent(EventArgs e)
{
EventHandler eh = ChildEvent;
if (eh != null)
eh(this, e);
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
I guess my point was that for example formClosing is already an event and here we are actually going to raise another event. So in effect we are using and event to raise an event. It actaully worked for me that way and I appreciate your help but it seems kinda hackish to me. Is it accepted to do it that way?
|
|
|
|
|
If there's already an event then raise it directly by either
1. Doing whatever it is that raises the event.
For FormClosing you could call just Close() in the child.
2. Calling the OnXxx method that raises the event.
For FormClosing (set the event args parameters as you need to if there are any)
OnFormClosing(new FormClosingEventArgs(CloseReason.UserClosing, false));
3. Override the OnXxx method that raises the event and call your override.
protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
} Note: Doing 2 or 3 will not cause the form to actually close as that is done in the Close method which internally calls the OnFormClosing(FormClosingEventArgs e) method.
[Edited for typos!]
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Ok that's great actually but how can I override the FormClosingEvenArgs? I tried the following and I even created a special eventArgs that inherits FormClosingEventArgs but it doesn't accept it.
protected override void OnFormClosing(FormClosingEventArgs e)
{
orderedBooks = GenerateBookList();
CreateOrderEventArgs2 args2 = new CreateOrderEventArgs2(orderedBooks);
base.OnFormClosing(args2);
}
|
|
|
|
|
If you actually want the book list to be generated when the form closes then there are a couple of ways.
The simplest is to override the OnFormClosing (example 3 in last post). In the commented section after the base event is raised, check Cancel and if false, raise acustom event.
It is possible to customize the FormClosing. FormClosingEventArgs derive from CancelEventArgs, so we can do something similar. The code below works. It's a little more complicated than the first option but this way only the one event is fired.
public partial class Form1 : Form
{
public new event EventHandler<CreateOrderEventArgs> FormClosing;
private List<BookOrder> orderedBooks;
public Form1()
{
InitializeComponent();
}
List<BookOrder> GenerateBookList()
{
List<BookOrder> result = new List<BookOrder>();
return result;
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
EventHandler<CreateOrderEventArgs> eh = FormClosing;
if (eh != null)
{
orderedBooks = GenerateBookList();
CreateOrderEventArgs createOrderEventArgs = new CreateOrderEventArgs(
e, orderedBooks);
eh(this, createOrderEventArgs);
}
}
}
public class CreateOrderEventArgs : CancelEventArgs
{
private CloseReason m_CloseReason;
private List<BookOrder> m_OrderedBooks;
public CreateOrderEventArgs(
FormClosingEventArgs e, List<BookOrder> orderedBooks)
{
m_CloseReason = e.CloseReason;
Cancel = e.Cancel;
m_OrderedBooks = orderedBooks;
}
public CloseReason CloseReason
{
get { return m_CloseReason; }
}
public List<BookOrder> OrderedBooks
{
get { return m_OrderedBooks; }
}
}
public class BookOrder
{
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
|
Simple question this, there may not be an answer but hoping someone may know.
I have a toolStrip with a number of buttons. The toolStrip is a great choice as it handles the positioning and size of the button based on their text. It also has the visual style I am needing to use.
My problem is the tool strip likes to draw a stupid line at the bottom, which is ok in instances where the tool strip is over lapped by a panel or something. But when I need the buttons to appear in the middle of a panel, for example, the line in question is unacceptable.
Now I can think of long ways around this, like creating my own buttons, handling the paint event, or even overlapping a small panel which matches the bg and covers the line.
I was just hoping someone may know of a property or something that i may have overlooked that can solve my issue without the hassle.
Thanks if anyone can help, if not im sure ill just end up creating a custom button container or something
|
|
|
|
|
Nope, you're gonna have to handle the paint event yourself.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Done now, and if anyone whats to know, here is what i did.
Created userControl that inherits from ToolStrip
Then overrided the painting with the following code - very simple really;
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.FillRectangle(new SolidBrush(this.Parent.BackColor), 0, this.Height - 2, this.Width + 1, this.Height + 1);
}
Note: the 1 and 2 constant values used where the first I tried and worked so not checked to see if 0 and 1 would have worked
|
|
|
|
|
hi all
plz help me.............
i want to access file which is present on another server..........
.
.
e.g suppose i want to get all file information using "fileinfo"
if file filename.txt is present on http://www.abcd.com/file/filename.txt
and my application is on http://www.zyx.com/homepage.aspx
.
and my code is present in homepage.aspx
.
and i want to retrieve "filename.txt" . lastaccesstime etc..
.
then what should i used to access that file..........
i used server.mappath(.....) but it is used for my application.......
so anyone please suggest me that how to access that file...
using url string........
waiting for reply...........
...........................
|
|
|
|
|
you could FTP to the server, download the file then do whatever you want with it.
course you will need FTP access privilages.
If this is an option, do a search for 'C# FTP' or something. Its actually not too much code to download a file.
|
|
|
|
|
You can't do this using anything in the System.Io namespace if the file is behind a web server. Those classes will not work over HTTP.
The information you want would have to be exposed by the web server, probably using a web service, or, if the site was poorly run, exposed by directory browsing being turned on in the web server.
|
|
|
|
|
i tried it but its not working......
.
.
my problem is ........
suppose im having two servers...
.
and im using.
.
http://www.oneserver.com/files
and http://www.sendserver.com/files
.
where files is a directory containg list of files.
.
.
and i hav to maintain the list of changed files with creation time, last access times, new files uploaded to that location etc...
.
.
so how to map that paths.
.
my applciation is running on
http://www.oneserver.com/myapplication.aspx
i tried it using server.mappath("files/filename.txt");
it is working for oneserver only.......
but through that application means http://www.oneserver.com/myapplication.aspx
i want to access http://www.secondserver.com/files..
and my code is thr in http://www.oneserver.com/myapplication.aspx.
.
to how to access secondserver.com/files through that code..
.
i tried it several ways but still not getting how to do it.
.
.
please help me.
.
thanks in advanced...
...........................
|
|
|
|
|
Of it's not working! I just got done tell you that it's not going to work.
You can't map a drive letter to an http:// path. Webservers doesn't support what you want to do. You have to use some other server on those boxes to get the information you want, such a FTP.
|
|
|
|
|
but will u please tell me how to achieve it
.
.
...........................
|
|
|
|
|
I already did. You have to use a different server, like FTP, on those site in which you want to do this. You can NOT accomplish this at all using a web server (Http). If you don't control these web sites, there's nothing you can do about it.
|
|
|
|
|
dear, mr. dave
.
.
im also having another problem in accessing file from server.
.
e.g. if file is stored on c:\inetpub\wwwroot\myfiles\filename.txt
and im accessing it using
FileStream fs = new FileStream(@"http://localhost/myfiles/filename.txt", FileMode.Open, FileAccess.Read);
then file in not being accessed.
.
will u plz tell me how to achieve this.
.
actually im a newbie to c#.net
thanks in advanced......
.
.
...........................
|
|
|
|
|
For the last time. You can NOT user anything in the System.Io namespace on files and folders that begin with "http://". You cannot open files through a web server.
You have to use a path the start with a drive letter or UNC path. Using a URL will not work. If you're trying to access a file from the browser side, and the file is on the server, you can't.
sushilbondre wrote: actually im a newbie to c#.net
...and to networking and web technologies too.
|
|
|
|
|
I'm trying to, as the subject line suggests, retrieve a single row from a table with the table's primary key, then edit the row's columns before updating the row to save my changes.
Am I way off here? I'm not sure how to update an existing row.
EdsDBDataSet.VideoRow videoRow = edsDBDataSet.Video.FindByVideo_ID(int.Parse(txtID1.Text));
videoRow.Video_Description = txtDescription.Text;
|
|
|
|
|
Hi,
For my web application, I am creating a text file that is stored in a shared network folder. This file needs to have a generic name (ie Text.txt) and each subsequent file will be named with incrementing numbers(Text2.txt then Text3.txt, etc). How do I create the function that will open the target folder, look to see what the last created file was and then create the new file with the appropriate number added to the filename? I also need to pass the created file name to my second webform where it will be monitored.
I want to execute the creation of the text file on a button click.
Thanks in advance for any help given!
|
|
|
|
|
I'd start with checking if the folder exists, if so I would count the number of txt files in there (frankly I would use a different extension, simply because other people can drop .txt files in there) and I would count how many exist. Then I would take that number, add a 1 to it and create my "Text" & i.ToString & ".ext" and close it up.
I use i to count.
Enjoy
|
|
|
|