Click here to Skip to main content
15,887,135 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
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 
GeneralRe: 42 method Pin
Daniel Pfeffer27-Sep-16 2:39
professionalDaniel Pfeffer27-Sep-16 2:39 
GeneralRe: 42 method Pin
Nathan Minier27-Sep-16 2:49
professionalNathan Minier27-Sep-16 2:49 
GeneralO_O Pin
Brisingr Aerowing19-Sep-16 8:29
professionalBrisingr Aerowing19-Sep-16 8:29 
GeneralRe: O_O Pin
enhzflep30-Sep-16 23:59
enhzflep30-Sep-16 23:59 
GeneralCultural mess Pin
Bernhard Hiller15-Sep-16 21:13
Bernhard Hiller15-Sep-16 21:13 
GeneralRe: Cultural mess Pin
Jörgen Andersson15-Sep-16 23:21
professionalJörgen Andersson15-Sep-16 23:21 
GeneralRe: Cultural mess Pin
Bernhard Hiller16-Sep-16 0:11
Bernhard Hiller16-Sep-16 0:11 
GeneralRe: Cultural mess Pin
Nelek16-Sep-16 0:50
protectorNelek16-Sep-16 0:50 
GeneralQuick! Someone send me an email! Pin
PIEBALDconsult14-Sep-16 16:14
mvePIEBALDconsult14-Sep-16 16:14 
GeneralRe: Quick! Someone send me an email! Pin
Bernhard Hiller14-Sep-16 21:01
Bernhard Hiller14-Sep-16 21:01 

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.