Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
if checked checkbox chksetting,then login admin access only setting form not click other button like frmmanual ..(name of check box chkSettings , chkmanual there are 2 check boxes & name of my form frmsetting,frmmanual,frmhome) in frmhome add button (btnmanual,btnsetting)when i click btnsetting then open setting form & then btnmanual not open form on button click c# windows application?


What I have tried:

C#
private void btnSettings_Click(object sender, EventArgs e)
        {
            //frmSettings setting = new frmSettings();
            //this.Hide();
            //setting.ShowDialog();
            //this.Close();

            try
            {
                if (lblAuth.Text == "yes")
                {
                    var Setting = frmLogin.FormHome;
                    frmSettings setting = new frmSettings();
                    dal.change_screen(Setting, setting);
                    this.Hide();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "btnSettings_Click,frmHome", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
           }
Posted
Updated 31-Mar-21 23:24pm
v3
Comments
Maciej Los 1-Apr-21 3:48am    
What's the question?
Member 11893460 1-Apr-21 4:46am    
using checkbox checked permission form access,suppose if checked checkbox chksetting,then login admin access only setting form not click other button like frmmanual ..(name of check box chkSettings , chkmanual there are 2 check boxes & name of my form frmsetting,frmmanual,frmhome) in frmhome add button (btnmanual,btnsetting)when i click btnsetting then open setting form & then btnmanual not open form on button click c# windows application
Maciej Los 1-Apr-21 5:08am    
Sorry, but your question is unclear...
Member 11893460 1-Apr-21 5:41am    
actaually if i click the button then not open form,if user has no permission & if user have permission open form (username b this user access open form1 if permission & username a has no permission access form1 )
Member 11893460 1-Apr-21 5:47am    
i have done code but one problem there,i take value from database checkbox inserted value (yes ,no)if select then save in database yes & unselect then save no

It sounds like you need to implement "roles based security"

Here are some starting points for your research
Controls Based Security in a Windows Forms Application - Simple Talk[^]
Introduction to Role-Based Security in .NET[^]
 
Share this answer
 
Comments
Maciej Los 1-Apr-21 5:58am    
5ed!
C#
using System.Security.Principal;

public static class Global
{
    public static bool UserIsInRole(string role)
    {
        WindowsIdentity  identity = WindowsIdentity.GetCurrent();
        WindowsPrincipal principal = new WindowsPrincipal(identity);
        return principal.IsInRole(role);
    }

    public static bool UserIsInRole(WindowsBuiltInRole role)
    {
        WindowsIdentity  identity = WindowsIdentity.GetCurrent();
        WindowsPrincipal principal = new WindowsPrincipal(identity);
        return principal.IsInRole(role);
    }
}


Usage:
C#
bool isAdmin = Global.UserIsInRole(WindowsBuiltInRole.Administrator);
or...
C#
bool hasRole = Global.UserIsInRole("Developer");


Since we can't actually see your code or possible know everyplace you'd want to restrict access by role, you're going to have to determine where and how to implement this. My personal preference is to control access by implementing the role check in menus or at buttons in forms, enabling items that the user can use, and disabling the ones they can't.
 
Share this answer
 
Comments
Maciej Los 1-Apr-21 5:58am    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900