.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Do I have to use a UserControl with palette?

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
JamesMaeding
567 Views, 2 Replies

Do I have to use a UserControl with palette?

Every example I see for a palette has a usercontrol instead of regular controls on it.

Is that a requirement, or does it have some advantage?

 

It might be right in front of me I just cannot remember.

thx


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

2 REPLIES 2
Message 2 of 3
norman.yuan
in reply to: JamesMaeding

A Palette is added into a PaletteSet by the method PaletteSet.Add(Windows.Forms.Control) (let's not talk about WPF/Webpage here, for now). as you can see, as long as the object you passed in is a Control, it will become a Palette in the PaletteSet container.

 

So, I'd say, yes, you can use regular Win form controls, if you choose so. However, there are a couple of things that quite obvious you may not want to it this way:

 

1. PaletteSet, as a control/palette container, does not provide a design mode UI for you to easily layout a palette;

 

2. More important, each control added into PaletteSet, by calling its Add() method, become a Palette. In most case, if not all cases, a single control palette, is pretty much use less. If the single control you want to use is a container itself, such as Group box, Tab control, then you obviously need to add more "regular" controls (labels, text boxes...) into it. If it is the case, Yes, you can just write code to instantiate a group box, add other labels/text boxes into it and eventually add it into PaletteSet as a palette. But there is no design surface to help you layout the controls;

 

Following code works for me: it add a GroupBox as a palette, which inturn contains a label; it also add a label direcctly into the PaletteSet as palette:

 

using System;
using System.Drawing;
using WinForm = System.Windows.Forms;
using Autodesk.AutoCAD.Windows;

namespace PaletteSetWithoutUserControl
{
    public class MyPaletteSet : PaletteSet
    {
        public MyPaletteSet():base("","", new Guid("32F91297-FD59-47EA-933C-70A0383CE5E5"))
        {

            WinForm.Control palette1 = CreatePalette1();
            WinForm.Control palette2 = CreatePalette2();

            Add("First Palette", palette1);
            Add("Second Palette", palette2);
        }

        private WinForm.Control CreatePalette1()
        {
            WinForm.GroupBox box = new WinForm.GroupBox();
            box.Text = "Palette 1";
            box.Dock = WinForm.DockStyle.Fill;

            WinForm.Label lbl = new WinForm.Label();
            lbl.Text = "Enter text:";
            lbl.Location = new Point(15, 15);
            box.Controls.Add(lbl);

            return box;
        }

        private WinForm.Control CreatePalette2()
        {
            WinForm.Label lbl = new WinForm.Label();
            lbl.Dock = WinForm.DockStyle.Fill;
            lbl.Text = "AAAAA";

            return lbl;
        }
    }
}

 But adding a non-container control as a palette does not provide much usability here; nor builing a UI without design surface makes things easier.

 

So, using userControl is just a way of "rapid development" to design UI. 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 3
JamesMaeding
in reply to: norman.yuan

Yah, minor detail - no UI design for a palette, didn't think about that.

I guess that alone is reason for a usercontrol.

 

Good explanation, all that you said makes sense once, much appreciated.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost