Click here to Skip to main content
15,894,460 members
Home / Discussions / C#
   

C#

 
Questionretaining alpha channels from 32bpp bmp Pin
Doof36911-Feb-09 5:01
Doof36911-Feb-09 5:01 
AnswerRe: retaining alpha channels from 32bpp bmp Pin
Dave Kreskowiak11-Feb-09 6:42
mveDave Kreskowiak11-Feb-09 6:42 
AnswerRe: retaining alpha channels from 32bpp bmp Pin
Guffa11-Feb-09 9:55
Guffa11-Feb-09 9:55 
AnswerRe: retaining alpha channels from 32bpp bmp Pin
Doof36912-Feb-09 4:32
Doof36912-Feb-09 4:32 
QuestionSend data from textbox to datagridview in a diferent form Pin
ZRF6911-Feb-09 3:58
ZRF6911-Feb-09 3:58 
AnswerRe: Send data from textbox to datagridview in a diferent form Pin
ByteBlocks11-Feb-09 4:09
ByteBlocks11-Feb-09 4:09 
AnswerRe: Send data from textbox to datagridview in a diferent form Pin
musefan11-Feb-09 4:16
musefan11-Feb-09 4:16 
AnswerRe: Send data from textbox to datagridview in a diferent form [modified] Pin
DaveyM6911-Feb-09 9:48
professionalDaveyM6911-Feb-09 9:48 
When you want to send the data, raise a custom event.
In the other form subscribe to that event and react accordingly.

Don't be tempted (as previously suggested) to send forms or textboxes as parameters (to constructors or methods) or static properties to other forms. It's bad design. You will end up coupling forms too closely together which is non OOP and will lead to maintanence nightmares as your application grows.

Basic outline below:
// Form1.cs
using System;
using System.Windows.Forms;
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        Shown += new EventHandler(Form1_Shown);
    }
    void Form1_Shown(object sender, EventArgs e)
    {
        Form2 form2 = new Form2();
        form2.TextUpdated += new EventHandler<TextUpdatedEventArgs>(form2_TextUpdated);
        form2.Show();
    }
    void form2_TextUpdated(object sender, TextUpdatedEventArgs e)
    {
        // Do your thing here
        Console.WriteLine(e.Text);
    }
}
// Form2.cs
using System;
using System.Windows.Forms;
public partial class Form2 : Form
{
    public event EventHandler<TextUpdatedEventArgs> TextUpdated;
    public Form2()
    {
        InitializeComponent();
    }
    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        OnTextUpdated(new TextUpdatedEventArgs(textBox1.Text));
    }
    protected virtual void OnTextUpdated(TextUpdatedEventArgs e)
    {
        EventHandler<TextUpdatedEventArgs> eh = TextUpdated;
        if (eh != null)
            eh(this, e);
    }
}
// TextUpdatedEventArgs.cs
using System;
public class TextUpdatedEventArgs : EventArgs
{
    private string m_Text;
    public TextUpdatedEventArgs(string text)
    {
        m_Text = text;
    }
    public string Text
    {
        get { return m_Text; }
    }
}


Dave
BTW, 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)

AnswerRe: Send data from textbox to datagridview in a diferent form Pin
Deresen11-Feb-09 10:12
Deresen11-Feb-09 10:12 
QuestionOverride desktop context menu [modified] Pin
pmcons11-Feb-09 3:55
pmcons11-Feb-09 3:55 
AnswerRe: Override desktop context menu Pin
jas0n2311-Feb-09 4:02
jas0n2311-Feb-09 4:02 
GeneralRe: Override desktop context menu Pin
pmcons11-Feb-09 4:06
pmcons11-Feb-09 4:06 
AnswerRe: Override desktop context menu Pin
Giorgi Dalakishvili11-Feb-09 4:56
mentorGiorgi Dalakishvili11-Feb-09 4:56 
GeneralRe: Override desktop context menu Pin
pmcons11-Feb-09 5:31
pmcons11-Feb-09 5:31 
QuestionA New Language In C# Pin
jas0n2311-Feb-09 3:50
jas0n2311-Feb-09 3:50 
AnswerRe: A New Language In C# Pin
musefan11-Feb-09 4:11
musefan11-Feb-09 4:11 
AnswerRe: A New Language In C# Pin
Pete O'Hanlon11-Feb-09 4:29
mvePete O'Hanlon11-Feb-09 4:29 
AnswerRe: A New Language In C# Pin
riced11-Feb-09 4:46
riced11-Feb-09 4:46 
GeneralRe: A New Language In C# Pin
PIEBALDconsult11-Feb-09 4:59
mvePIEBALDconsult11-Feb-09 4:59 
AnswerRe: A New Language In C# Pin
PIEBALDconsult11-Feb-09 5:05
mvePIEBALDconsult11-Feb-09 5:05 
GeneralRe: A New Language In C# Pin
jas0n2323-Apr-09 5:04
jas0n2323-Apr-09 5:04 
AnswerRe: A New Language In C# Pin
Guffa11-Feb-09 6:53
Guffa11-Feb-09 6:53 
QuestionForm Pin
mrithula811-Feb-09 2:36
mrithula811-Feb-09 2:36 
AnswerRe: Form Pin
EliottA11-Feb-09 2:40
EliottA11-Feb-09 2:40 
AnswerRe: Form Pin
musefan11-Feb-09 2:48
musefan11-Feb-09 2:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.