Click here to Skip to main content

Alex Perepletov - Professional Profile

Summary

2,930
Author
179
Authority
12
Debator
24
Editor
10
Organiser
133
Participant
0
Enquirer
No Biography provided
Member since Friday, January 31, 2003 (10 years, 3 months)

Contributions

Articles 6 (Writer)
Tech Blogs 0
Messages 14 (Lurker)
Q&A Questions 0
Q&A Answers 8
Tips/Tricks 1
Comments 2

Links

Reputation

For more information on Reputation please see the FAQ.

Privileges

Members need to achieve at least one of the given member levels in the given reputation categories in order to perform a given action. For example, to store personal files in your account area you will need to achieve Platinum level in either the Author or Authority category. The "If Owner" column means that owners of an item automatically have the privilege, and the given member types also gain the privilege regardless of their reputation level.

ActionAuthorAuthorityDebatorEditorEnquirerOrganiserParticipantIf OwnerMember Types
Have no restrictions on voting frequencysilversilversilversilverAdmin
Store personal files in your account areaplatinumplatinumSitebuilder, Subeditor, Supporter, Editor, Staff
Have live hyperlinks in your biographybronzebronzebronzebronzebronzebronzesilverSubeditor, Protector, Editor, Staff, Admin
Edit a Question in Q&AsilversilversilversilverYesSubeditor, Protector, Editor, Admin
Edit an Answer in Q&AsilversilversilversilverYesSubeditor, Protector, Editor, Admin
Delete a Question in Q&AYesSubeditor, Protector, Editor, Admin
Delete an Answer in Q&AYesSubeditor, Protector, Editor, Admin
Report an Articlesilversilversilversilver
Approve/Disapprove a pending ArticlegoldgoldgoldgoldSubeditor, Mentor, Protector, Editor, Staff, Admin
Edit other members' articlesSubeditor, Protector, Editor, Admin
Create an article without requiring moderationplatinumSubeditor, Mentor, Protector, Editor, Staff, Admin
Report a forum messagesilversilverbronzeProtector, Editor, Admin
Create a new tagsilversilversilversilverAdmin
Modify a tagsilversilversilversilverAdmin

Actions with a green tick can be performed by this member.


 
You must Sign In to use this message board.
Search this forum  
RantControl.GetStyle() should be public. Pin
Sunday, March 15, 2009 7:52 PM by Alex Perepletov
I have a recursive function on my form that sets backgrounds of all Controls on it to Color.Transparent. It was a happy function until the moment I put a DataGridView on the form. DataGridView doesn't support transparent color, and the function blew up in an exception.
 
I could put an empty try catch around the color assignment line, but that is just way too ugly of a "solution".
 
The only way to determine whether a Control supports transparent background is to call the GetStyle() function. Too bad it's protected. Is there any good reason for this function being protected and not public? No way someone is going to inherit from every control just to get to those flags.
 
As usual, Reflection saves the day. Write an extension method that gets the flag in question. Well, it would probably make sense to write an extension that exposes the GetStyle(), but I wanted more readability in my code.
 
Anyway, this is the extension method:
public static bool SupportsTransparentBackColor(this Control control)
{
	// Protected function GetStyle(ControlStyles flag) determines whether
	// a control supports transparent background color.
	Type t = control.GetType();
	MethodInfo miGetStyle = t.GetMethod(
		"GetStyle",
		BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy,
		null,
		new Type[] { typeof(ControlStyles) },
		null);
	// Let's see what that method returns.
	return (bool)miGetStyle.Invoke(control, new object[] {
		ControlStyles.SupportsTransparentBackColor
	});			
}
 
And that is how it's used (I wish there were extension Properties too)
if (ctl.SupportsTransparentBackColor())
{
	ctl.BackColor = Color.Transparent;
}

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 20 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid