Click here to Skip to main content
15,892,927 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# -Oracle- Access Pin
jschell11-Jan-12 9:36
jschell11-Jan-12 9:36 
QuestionWinforms Update form label from a class library Pin
Member 43365949-Jan-12 4:53
Member 43365949-Jan-12 4:53 
AnswerRe: Winforms Update form label from a class library Pin
BobJanova9-Jan-12 5:05
BobJanova9-Jan-12 5:05 
GeneralRe: Winforms Update form label from a class library Pin
Member 43365949-Jan-12 5:17
Member 43365949-Jan-12 5:17 
GeneralRe: Winforms Update form label from a class library Pin
BobJanova9-Jan-12 6:46
BobJanova9-Jan-12 6:46 
AnswerRe: Winforms Update form label from a class library Pin
RexGrammer9-Jan-12 8:11
RexGrammer9-Jan-12 8:11 
AnswerRe: Winforms Update form label from a class library Pin
Luc Pattyn9-Jan-12 8:15
sitebuilderLuc Pattyn9-Jan-12 8:15 
GeneralRe: Winforms Update form label from a class library Pin
DaveyM699-Jan-12 8:43
professionalDaveyM699-Jan-12 8:43 
I agree with Luc - this is not a good method. The class library should not have or need any knowlege of any UI control. The normal way would be to get the text from the BusinessLayer vie a getter or string GetXXX() method and deal with updating the text in the UI layer.

Luc's suggestion of passing a delegate is an alternative aproach which is also valid and allows the calling of the update code from the BusinessLayer without it needing information about the control - the actual update is still done in the UI layer. Delegates often confuse people but they're pretty simple so here is an example. I prefer other options but here is how it is done:

C#
// CommonObjects class library

namespace CommonObjects
{
    public delegate void UpdateText(string text);
}

C#
// BusinessLayer class library, references CommonObjects

using CommonObjects;

namespace BusinessLayer
{
    public class Strings
    {
        public static void RequestUpdateText(UpdateText updateText)
        {
            updateText.Invoke("New Text");
        }
    }
}

C#
// Presentation layer - a winforms app here with a TextBox (textBox) on the main form (FormMain instance),
// references CommonObjects

using System.Windows.Forms;
using CommonObjects;

public partial class FormMain : Form
{
    public FormMain()
    {
        InitializeComponent();
        RequestUpdateFromClassLibrary();
    }

    private void RequestUpdateFromClassLibrary()
    {
        BusinessLayer.Strings.RequestUpdateText(new UpdateText(UpdateTextBox));
    }
    private void UpdateTextBox(string text)
    {
        textBox.Text = text;
    }
}

Dave

Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.
Astonish us. Be exceptional. (Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)



AnswerRe: Winforms Update form label from a class library Pin
BillWoodruff10-Jan-12 6:17
professionalBillWoodruff10-Jan-12 6:17 
QuestionHow to access the control of a form from diffrent form? Pin
Paramu19739-Jan-12 4:08
Paramu19739-Jan-12 4:08 
AnswerRe: How to access the control of a form from diffrent form? Pin
Ravi Bhavnani9-Jan-12 4:15
professionalRavi Bhavnani9-Jan-12 4:15 
AnswerRe: How to access the control of a form from diffrent form? Pin
RexGrammer9-Jan-12 8:09
RexGrammer9-Jan-12 8:09 
AnswerRe: How to access the control of a form from diffrent form? Pin
DaveyM699-Jan-12 9:07
professionalDaveyM699-Jan-12 9:07 
AnswerRe: How to access the control of a form from diffrent form? Pin
BillWoodruff10-Jan-12 6:55
professionalBillWoodruff10-Jan-12 6:55 
GeneralRe: How to access the control of a form from diffrent form? Pin
Paramu197310-Jan-12 19:03
Paramu197310-Jan-12 19:03 
Questiondesktop sharing Pin
Member 38923438-Jan-12 21:24
Member 38923438-Jan-12 21:24 
AnswerRe: desktop sharing Pin
RexGrammer9-Jan-12 1:56
RexGrammer9-Jan-12 1:56 
AnswerRe: desktop sharing Pin
Ravi Bhavnani9-Jan-12 2:06
professionalRavi Bhavnani9-Jan-12 2:06 
QuestionReading an image from an array of data on disk Pin
Subterranean8-Jan-12 1:36
Subterranean8-Jan-12 1:36 
AnswerRe: Reading an image from an array of data on disk Pin
Luc Pattyn8-Jan-12 1:46
sitebuilderLuc Pattyn8-Jan-12 1:46 
GeneralRe: Reading an image from an array of data on disk Pin
harold aptroot8-Jan-12 4:06
harold aptroot8-Jan-12 4:06 
AnswerRe: Reading an image from an array of data on disk Pin
Luc Pattyn8-Jan-12 4:46
sitebuilderLuc Pattyn8-Jan-12 4:46 
GeneralRe: Reading an image from an array of data on disk Pin
harold aptroot8-Jan-12 4:55
harold aptroot8-Jan-12 4:55 
AnswerRe: Reading an image from an array of data on disk Pin
Luc Pattyn8-Jan-12 5:08
sitebuilderLuc Pattyn8-Jan-12 5:08 
GeneralRe: Reading an image from an array of data on disk Pin
harold aptroot8-Jan-12 5:22
harold aptroot8-Jan-12 5:22 

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.