user defined control

Last Reply 10 days ago By kalpesh

Posted 10 days ago

Add User Defined Control [Button] .Add property 'security Level' 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PMS_Pro_Win.Custom_Controls
{
    public partial class btn : System.Windows.Forms.Button
    {
        public btn()
        {
            InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            
            if (SecurityLevel > 0)
            {
                base.Enabled = false;
            }
            else
            {
                base.Enabled = true;
            }
        }

        private int level;
        [Category("Security Level"), Description("Enter Security Level")]

        public int SecurityLevel
        {
            get
            {
                return level;
            }
            set
            {
                level = value;
                Invalidate();
            }
        }
    }
}

How to set property give by varibale name which is declare in another Class file 

You are viewing reply posted by: kalpesh 10 days ago.
Posted 10 days ago Modified on 10 days ago

You just need to set its property by user defined control name which you used in your Form with the name of user control in your Form like below.

usercontrolaliesName.SecurityLevel = 1;
//or
usercontrolaliesName.SecurityLevel = 0;

Check the below Sample code for your reference.

User control : btn

FORM : Form1

Form1.cs

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        btnSubmit.SecurityLevel = 1;
        //btnSubmit.SecurityLevel = 0;
    }
}

Screenshot

 

 

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html