Lupusregina Beta
Solution for lots of flags
Hi. When I need to have rights management in my programs, I usually make an enum "Rights" as [Flags] type long and do like
Invalid = -1,
None = 0,
AddGame = 1,
DelGame = 2,
LaunchGame = 4,
EditGame = 8
..etc
I like because it's simple bitwise and I made an extension method so I can just do like
function DeleteGame(Game game) {
if (!ActiveUser?.Rights.HasPermission(Rights.DeleteGame) ?? false) return;
However... I'm doing a big complex app and it's gonna have more rights than I have bits in a long. What is a good way to handle it at that point? I figured I could do enums like
Rights_Context1
Rights_Context2
..etc
then I was trying to figure out how to store them in the user. I figured maybe
public List<Enum> Rights
then load them all into there, but then how do I check them? Loop and check what type each entry is then compare? That seems awkward.
Is there any easy solution for having large amounts of flags in an enum? I assume I need a bitwise enum because I want to store the data in the db, and a bigint seemed the easiest way. I suppose I could do a permissions related table then make single entries per flag but that seems very inefficient.
20 replies
Control getting resized when adding to FlowLayoutPanel
Hi. I have a weird problem. I have a FLP and I'm adding controls to it. I have four UserControl classes, each is 865 wide. Three of them are fine when I add, but when I add CtrlImage usercontrol it goes to 1298 wide. In trying to nail it down, I've removed all code from the class so it isn't doing anything crazy. It just has a single label and picturebox. I determined when it happens:
Control ctrl = col.GetControl();
MessageBox.Show("1: " + ctrl.Width.ToString());
record.Controls.Add(ctrl);
MessageBox.Show("2: " + ctrl.Width.ToString());
When I run this, I get "1: 865" and "2: 1298". What the heck happens when you add a control to a FLP that would cause it to expand? I tried asking GPT, it suggested I set AutoSize false and Dock to none on ctrl and WrapContents to true on the FLP. None of that made any difference. The only fix is to do ctrl.Width = 865 after I've added it.
I suppose that resolves it, but I really don't like not knowing why that happened and I'm sure this "band aid" is not a real fix. Anyone know what may cause this?
Thanks!
4 replies