How to show a label after it has been created in code

Hi there. I have created a NSTextField using code (see below) and am now trying to display it.

Could someone please tell me how this can be done.

NSTextField Label = new NSTextField
{
Frame = new RectangleF (18f, 362f, 134, 17),
Alignment = NSTextAlignment.Left,
};

Button.Activated += (object sender, EventArgs e) =>
{
Label.StringValue = TextEntry.StringValue <----- TextEntry is a Text Entry Field
//show the NSTextField
}

Any help is appreciated.

Thanks in advance,
Ben.

Posts

  • MichaelBothMichaelBoth AUMember ✭✭✭

    My understanding is you always need to add dynamically created controls as subviews to the view where you wish it to appear. So, for example:
    Window.ContentView.AddSubview(Label)

    I tried your example in an overridden CustomAwakeFromNib for a test form, and the label appears.

  • BenFortinBenFortin CAMember

    Thank you for your help. I ended up creating it in Xcode and then showing and hiding it as needed.

Sign In or Register to comment.