Click here to Skip to main content
15,888,579 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Paid per line of code??? Pin
ZurdoDev29-Sep-16 7:46
professionalZurdoDev29-Sep-16 7:46 
GeneralRe: Paid per line of code??? Pin
jeron129-Sep-16 8:28
jeron129-Sep-16 8:28 
GeneralRe: Paid per line of code??? Pin
F-ES Sitecore29-Sep-16 23:48
professionalF-ES Sitecore29-Sep-16 23:48 
GeneralRe: Paid per line of code??? Pin
WiganLatics30-Sep-16 1:34
professionalWiganLatics30-Sep-16 1:34 
GeneralRe: Paid per line of code??? Pin
den2k884-Oct-16 2:07
professionalden2k884-Oct-16 2:07 
GeneralRe: Paid per line of code??? Pin
jgakenhe29-Sep-16 8:34
professionaljgakenhe29-Sep-16 8:34 
GeneralRe: Paid per line of code??? Pin
Nathan Minier29-Sep-16 9:21
professionalNathan Minier29-Sep-16 9:21 
GeneralRe: Paid per line of code??? Pin
Bernhard Hiller29-Sep-16 20:43
Bernhard Hiller29-Sep-16 20:43 
GeneralRe: Paid per line of code??? Pin
Nathan Minier30-Sep-16 1:42
professionalNathan Minier30-Sep-16 1:42 
GeneralRe: Paid per line of code??? Pin
CDP18022-Oct-16 11:17
CDP18022-Oct-16 11:17 
GeneralRe: Paid per line of code??? Pin
Nathan Minier3-Oct-16 1:10
professionalNathan Minier3-Oct-16 1:10 
GeneralRe: Paid per line of code??? Pin
CDP18023-Oct-16 5:48
CDP18023-Oct-16 5:48 
GeneralRe: Paid per line of code??? Pin
V.29-Sep-16 20:50
professionalV.29-Sep-16 20:50 
GeneralRe: Paid per line of code??? Pin
F-ES Sitecore29-Sep-16 23:47
professionalF-ES Sitecore29-Sep-16 23:47 
GeneralRe: Paid per line of code??? Pin
V.29-Sep-16 23:48
professionalV.29-Sep-16 23:48 
GeneralRe: Paid per line of code??? Pin
F-ES Sitecore29-Sep-16 23:54
professionalF-ES Sitecore29-Sep-16 23:54 
GeneralRe: Paid per line of code??? Pin
V.29-Sep-16 23:54
professionalV.29-Sep-16 23:54 
GeneralDocking and Anchoring Pin
Alan N27-Sep-16 3:22
Alan N27-Sep-16 3:22 
Control docking and anchoring are well understood by everybody and we all know that the two techniques are mutally exclusive. The help pages says something like "Only one can be set at a time, and the last one set takes precedence".

I've always believed what I'm told by my elders and betters and was certain that code like the following would create an anchored control.
C#
FancyControl fc = new FancyControl();
fc.Anchor = AnchorStyles.Top | AnchorStyles.Left;
SomePanel.Controls.Add(fc);


My FancyControl would typically be used fully docked and the constructor helpfully presets that condition. On the very rare occasion it should be anchored then just assign a value as shown.

Why oh why then, did the control remained dicked?
C#
FancyControl fc = new FancyControl();
Debug.Print("Dock: {0} Anchor: {1}", fc.Dock, fc.Anchor);
// Dock: Fill Anchor: Top, Left
fc.Anchor = AnchorStyles.Top | AnchorStyles.Left;
SomePanel.Controls.Add(fc);

On reading the Anchor property all became clear as the value was already Top|Left. Perhaps the Anchor property ignores redundant assignments? Of course it does and a delve into the published reference source confirms this. Search for DefaultLayout.SetAnchor in Reference Source[^] if you are interested.

The final solution for the simple task of setting the control's anchor property is
C#
FancyControl fc = new FancyControl();
fc.Dock = DockStyle.None;
SomePanel.Controls.Add(fc);

OK I should have included the statement fc.Anchor = AnchorStyles.Top | AnchorStyles.Left; after undocking but it's redundant!

AlanN
aka Alan "2f hours debugging" N
GeneralRe: Docking and Anchoring Pin
Marc Clifton27-Sep-16 4:09
mvaMarc Clifton27-Sep-16 4:09 
GeneralRe: Docking and Anchoring Pin
TheGreatAndPowerfulOz27-Sep-16 4:41
TheGreatAndPowerfulOz27-Sep-16 4:41 
GeneralRe: Docking and Anchoring Pin
Clifford Nelson27-Sep-16 5:54
Clifford Nelson27-Sep-16 5:54 
General42 method Pin
Indivara22-Sep-16 13:54
professionalIndivara22-Sep-16 13:54 
JokeRe: 42 method Pin
Midi_Mick22-Sep-16 23:18
professionalMidi_Mick22-Sep-16 23:18 
GeneralRe: 42 method Pin
Jeremy Falcon26-Sep-16 7:09
professionalJeremy Falcon26-Sep-16 7:09 
GeneralRe: 42 method Pin
Nathan Minier27-Sep-16 1:46
professionalNathan Minier27-Sep-16 1:46 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.