CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Join Date
    Mar 2008
    Posts
    26

    Visual Studio - How can i stop ctrl+E and D from removing my white spaces?

    Hay ho everybody :-)

    I've gotten very tired of making some of my lines of code nicely indented using TAB and then having ctrl+E and D removing them all :-/

    For instance.

    Code:
     
        Button btnCalculate = new Button();
            EventHandler hndCalculateFinalGradeHandler;
    Becomes...

    Code:
     
        Button btnCalculate = new Button();
        EventHandler hndCalculateFinalGradeHandler;
    B4 anyone says to just stop using ctrl+E and Dm I find it very usefull for getting a general layout when i'm in a lazy mood heheh

  2. #2
    Join Date
    Jul 2008
    Posts
    70

    Re: Visual Studio - How can i stop ctrl+E and D from removing my white spaces?

    Why are you identing that line? I fail to see any rule you could give so a machine could know why you choose to ident that way and not indent

    int i;
    int j;

    the same way.

    So in short I think what your looking for is impossible. But I could be wrong.

  3. #3
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Visual Studio - How can i stop ctrl+E and D from removing my white spaces?

    in essence, i agree with compavalanche.. your first code sample is much uglier than the second. if you wish to distinct Events from member variables, use regions, not indentation. indentation indicates scope.. dont violate established rules please, you might not be the only person who has to maintain your code
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  4. #4
    Join Date
    Mar 2008
    Posts
    26

    Re: Visual Studio - How can i stop ctrl+E and D from removing my white spaces?

    Well, i'm learning event handlers, and being able to see at a quick glance weather the event handler declarations, registering, association with a certain event like .Click ect are in my code by simply seeing if theres an indent in the 130 lines of code makes it alot easer to read.....

    I'm not sure what you mean by regions.... could you give me an example? thx

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Visual Studio - How can i stop ctrl+E and D from removing my white spaces?

    Use regions as suggested. Indenting here just goes against convention so much it's almost criminal.

    Code:
    #region Buttons
    
    Button btnCalculate = new Button();
    Button btnTardy = new Button();
    
    #endregion Buttons
    
    #region Button Event Handlers
     
    EventHandler hndCalculateFinalGradeHandler; 
    EventHandler hndCalculateTardyHandler; 
    
    #endregion Button Event Handlers
    P.S generally the end regions are usually typed as
    Code:
    #endregion
    For readability, I typed them with the same tag as the opening region, e.g.
    Code:
    #endregion Buttons
    I like this so much, I have a patent on it.

    Btw, regions can be collapsed as well (or nested but that's another discussion).

    Collapsed, the above regions would look something like:
    Code:
    + Buttons
    
    + Button Event Handlers

  6. #6
    Join Date
    Mar 2008
    Posts
    26

    Re: Visual Studio - How can i stop ctrl+E and D from removing my white spaces?

    But thats not very encapsulated though (yes i know thats not the 110% correct useage of the word, but the point is u understand what i am saying), I like to keep everything for that button right next to each other, it makes editing said button alot simpler, if I was to split it up into regions as above it would mean alot more jumping up and down though the code checking back and forth if this has that and does this have that.... thats just gonna cause posible errors for a learner

    Code:
            # region "Calculate Final Grade" Button
            btnCalculate.Text = "Calculate Final Grade";
            btnCalculate.Location = new Point(5, 135);
            btnCalculate.Size = new Size(400, 25);
                hndCalculateFinalGradeHandler = new EventHandler(BtnCalculate_Click);
                btnCalculate.Click += hndCalculateFinalGradeHandler;
            Controls.Add(btnCalculate);
            # endregion "Calculate Final Grade" Button
    The regions are gonna be damned usefull though, allways hoped there was a way to create a shrinkable area, cheers :-)

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Visual Studio - How can i stop ctrl+E and D from removing my white spaces?

    You know, all the code you are writing gets written for you by the forms designer.

  8. #8
    Join Date
    Jul 2008
    Posts
    70

    Re: Visual Studio - How can i stop ctrl+E and D from removing my white spaces?

    Can you just use another scope block:

    Code:
            # region "Calculate Final Grade" Button
            btnCalculate.Text = "Calculate Final Grade";
            btnCalculate.Location = new Point(5, 135);
            btnCalculate.Size = new Size(400, 25);
            {
                hndCalculateFinalGradeHandler = new EventHandler(BtnCalculate_Click);
                btnCalculate.Click += hndCalculateFinalGradeHandler;
            }
            Controls.Add(btnCalculate);
            # endregion "Calculate Final Grade" Button

  9. #9
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Visual Studio - How can i stop ctrl+E and D from removing my white spaces?

    Quote Originally Posted by compavalanche
    Can you just use another scope block:

    Code:
    # region "Calculate Final Grade" Button
    btnCalculate.Text = "Calculate Final Grade";
    btnCalculate.Location = new Point(5, 135);
    btnCalculate.Size = new Size(400, 25);
    {
    hndCalculateFinalGradeHandler = new EventHandler(BtnCalculate_Click);
    btnCalculate.Click += hndCalculateFinalGradeHandler;
    }
    Controls.Add(btnCalculate);
    # endregion "Calculate Final Grade" Button
    Oh goodness NOOOO ! This would cofuse any foreign reader of your code. I would always look why the block is in brackets, looking for any condition which jumps into it or mybe ignores this part of code. If you have such a lot of code really in one form ( for example 30 buttons, 10 listboxes, 20 combos 3 TabControlers cascaded into each other for a very complex Userinterface
    a) you can devide your class in partial classes
    b) Overthink your design. Is this really useable without reading hundret pages of explnations before.

    People in general I think dislike to read user guides. They want to sit down in fromt of the PC, opening your program and it should be in a shape people dosn't get confused by it !
    If you do in that way...
    There will not be any problem to loose track over your code.

    Your system putting together all code of a single control, excuse me, seems me a bit of short sighted,
    Think to a textbox , a listbox and a button. You may want all of them to interact with each other for example filing some text in the zextbox pressing a button and by that filling the text into the list.

    Where do you plac this code together. All to the button ? to The textbox validation event ? To the listbox becuase you need Add method there ?

    Organize your code by logical needs. Or maybe you will sort them by Regions like Fields, Constuctors, Properties ( suboder into public and private if needed ), Methods, delegates, overrides. permanently keeping one system in all of your code makes it easy for you to maintain your code for years. The above system -- Never, no way.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  10. #10
    Join Date
    May 2006
    Posts
    306

    Re: Visual Studio - How can i stop ctrl+E and D from removing my white spaces?

    Could you just use a region, then indent the region name like this...

    Code:
    #region |   REgionText (EventHandler hndCalculateFinalGradeHandler;)
    #endregion
    It will look like this...
    Code:
    rssView.NextArticle();
    rssDescriptionView.DisplayItem = rssView.SelectedItem;
    |   RegionText
    OR
    Code:
    rssView.NextArticle();
    rssDescriptionView.DisplayItem = rssView.SelectedItem;
    -   RegionText
    OR
    Code:
    rssView.NextArticle();
    rssDescriptionView.DisplayItem = rssView.SelectedItem;
    +   RegionText
    Seems that spaces will just erase unless it is after another character...

    There is no other way.

  11. #11
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Visual Studio - How can i stop ctrl+E and D from removing my white spaces?

    Quote Originally Posted by code?
    Could you just use a region, then indent the region name like this... ....There is no other way.
    ????
    I dont get what you want to communicate wth this.
    You can use region and endregion and if you want you can Tab the regions so they dont begin in the left side something like
    Code:
    public class MyClass{
      #region private Fields
    	 private bool understanding = false;
    	 private bool itsEasy = true;
    	 //... all your fields
      #endregion 
      #region ctors
      ///<summary>
      /// This Class does nothing and is only to demonstrate regions 
      ///and  summary
      ///</summary>
      public MyClass(int whatever){
    	 //... whatever
      } 
      // other Ctors...
     
     #endregion
     // and so on
     
    }
    Simple try it and you will see how this works. Also use the class in a demo and look what the intellisense shows you. You can use summaries for getting text to all your properties and methods of a class.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  12. #12
    Join Date
    Mar 2008
    Posts
    26

    Re: Visual Studio - How can i stop ctrl+E and D from removing my white spaces?

    Ha :-)
    Thx alot for all ya help, im going with just regioning out the handlers themselves then shrinking, the gray region box is very easy to see when i scan through my code and does the job perfectly, thx alot :-)

    As far as what to put where as JonnyPoet was saying, my current way of doing it is to place all the dot notation attributes that set up said object like .Text and .Size together and also have the event handler instantiaion with them which has the method name
    hndResetButtonHandler = new EventHandler(BtnReset_Click);
    and its registration line with the event
    btnReset.Click += hndResetButtonHandler;
    and the Controls.Add(btnReset); line too.
    The method that runs is of course gonna be seperate and lower down in my code but the instantiation line shows me the methods name.
    I havn't gotten to the stage of having multiple events per object in my form yet so it might change then, but I don't see why when they will just be a further event handler line in there, but like i said I havn't gotten that far yet so i can't really comment..... :-)

    Quote Originally Posted by Arjay
    You know, all the code you are writing gets written for you by the forms designer.
    Yes, but the book i'm learning from doesn't teach via visual studio (it's no biggy trust me, im using visual studio) so it's teaching me all these lines ect which i think as a learner is it's good to learn b4 lettign visual studio do that for me :-)

  13. #13
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Visual Studio - How can i stop ctrl+E and D from removing my white spaces?

    Quote Originally Posted by Zirus Blackheart
    But thats not very encapsulated though (yes i know thats not the 110% correct useage of the word, but the point is u understand what i am saying)
    Er, no. Actually, especially when you talk to a programmer, using a word that you assert means Y when it actually means X, is not a good idea.
    For example, tell me to format your C drive, than come back and exclaim "oh no! why arent all my files and folders nicely formatted into TitleCase? Thats what I meant by format!"


    I like to keep everything for that button right next to each other, it makes editing said button alot simpler,
    Aside from the fact that you can never put all code that refers to your button in the same block (what happens if you say MyButton1.Text = "Hello" in the middle of a constructor? OH NO! IT'S NOT NEAR WHERE THE BUTTON WAS DEFINED! Better move it, and then add a GoTo into the constructor right? That makes for way more readable code. (i.e. trying to put all code for a button in one place is silly as well as impossible)

    I was to split it up into regions as above it would mean alot more jumping up and down though the code checking back and forth if this has that and does this have that.... thats just gonna cause posible errors for a learner
    Oh, come on! it sounds like making arguments for arguments sake. You need to stop dedicating yourself to learning a path that NOONE else uses. It wont make you able to integrate into the world of programmers out there at all (development *teams*?)
    Nothing stopping you using regions like:

    Code:
    #region All My Button1 Stuff
    //button1 stuff
    #endregion
    
    #region All My Button2 Stuff
    //button2 stuff
    #endregion
    But it still doesnt violate the point that indentation is universally understood to signify scope. Same scope? Same indentation. Dont break these rules because they are what we all play by. If you one day want some help and post on a forum, a real dog's dinner of a code block, then people are going to be very reluctant to help you
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  14. #14
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Visual Studio - How can i stop ctrl+E and D from removing my white spaces?

    Quote Originally Posted by Zirus Blackheart
    Ha :-)
    Thx alot for all ya help, im going with just regioning out the handlers themselves then shrinking, the gray region box is very easy to see when i scan through my code and does the job perfectly, thx alot :-)
    How you justify writing 3 lines of code where one will do, on the proviso that the 3 will shrink to 1, hence take up the same amount of code as the original line of code?What did you gain?

    Code:
    Button b = new Button()
    #region Button b Event Handler
    ButtonHandler bevt = whatever
    #endregion
    
    Button b = new Button()
    [Button b Event Handler]
    Seriously.. what's the point? Anyone reading the code will know it's a handler, you dont need to label it for them any more than you need to write these comments:

    Code:
    //this is a button called b
    Button b = whatever
    //this is the button handler for b
    ButtonHandler bevt = whatever
    100% useless comments. Your code should be self documenting enough to convey this info. If you have to explain your code, you need to write it better



    As far as what to put where as JonnyPoet was saying, my current way of doing it is to place all the dot notation attributes that set up said object like .Text and .Size together and also have the event handler instantiaion with them which has the method name
    as in:
    Code:
    Button b = new Button()
    #region Button b Event Handler
    ButtonHandler bevt = whatever
    #endregion
    #region Button b Text assignment
    b.Text = "Hello"
    #endregion
    #region Button b Color assignment
    b.Color = Color.WHite
    #endregion
    Confusing to read, no?

    The method that runs is of course gonna be seperate and lower down in my code
    Funnily enough, when you drag your button onto a form and set its properties, the designer writes all that code, neatly clumped together in a separate class file for you. I believe arjay pointed this out

    Yes, but the book i'm learning from doesn't teach via visual studio (it's no biggy trust me, im using visual studio) so it's teaching me all these lines ect which i think as a learner is it's good to learn b4 lettign visual studio do that for me :-)
    Do you own a bicycle? Did you build it yourself? Did you stop by the spoke manufactureres and ask them how they forged the rods, or ask the tyre makers what compound the rubber is? When you make a cup of tea, do you disassemble the kettle to understand how it works before you boil it? Closer to home, did you look up how windows draws a button, or communicates the fact that you clicked on it? Probably not. There are some things in this life that you do not do because there is no point; putting vast amounts of time into learning something low level that you will never use (because it works, ain't broken and if it was you could easily learn then how to fix it at that time) . By all means create your UIs by hand, but consider that this sort of thing was delegated to a designer long ago because:

    It's easy for the designer to get it right, quickly
    It's easy for a human to get ir wrong, slowly
    It's tedious and repetitive and obeys simple logic, and computers excel at such tasks; humans do the higher-intelligence-requirement/varied-logic-required parts


    That said.. if your goal is to create java 2 microedition apps fopr old mobile phones using notepad, go right ahead
    Last edited by cjard; July 22nd, 2008 at 06:51 AM.
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  15. #15
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Visual Studio - How can i stop ctrl+E and D from removing my white spaces?

    Quote Originally Posted by Zirus Blackheart
    i DO NOT CARE! if its how it should look in the world of working as a coder!
    I AM NOT WORKING AS A CODER! it is ONLY for NOW while i'm learning for this one thiong right now, in 5 days time, THEY WONT BE INDENTED!
    ARGH!
    So the wisdom of "start as you mean to go on" and "do it right, first time" are somewhat lost on you? Trust me, in coding especially, you should always try to get things right first time and not put in hacks.. A cornerstone of the company I work for is a seriously nasty hack of an app that I wrote 3 years ago and lost the source code to. It's so vital and has so many little quirks that we spend too much time trying to work round, thatI truly wish I'd put my foot down at the start and demanded a month's dev time for it, not the 3 days I got. Its replacement exists in beta but keeps being shelved while the next big panic is overcome and while I'm amazed that it still works 3 years on, it's the bane of several lives. If you take nothing else away from this discussion, please.. Get the notion of getting it right, from the start. (Oh, and take regular backups.. I've never quite lived down the foolishness of not preserving my work before that day my hard disk started going ker-tick, ker-tick, ker-tick.. )


    Why the hell would I do that?
    Why would you say you wanted to do that, when you didnt?

    I wasn't talking about that at all,thats setting something in the button the damned place in your code when that setting of it should happoen!
    I fail to see a difference. You want everything related to a button in one place; you said so. In fact you want it all so-in-one-place that you cannot tolerate even a few lines distance from the "buttons declaration region" to the "event handler region" - so you seem to be wanting every item of code pertaining to a button, in one place?
    My aim here is to make you think about the logic behind the organisation of your code, and why we (professional developers) dont organise like that. There is a reason, usually championed by human laziness; we always find the easiest way of doing something, and that's often an efficient one that carries extra merit if it is defacto standard



    Yes I built my first bike (same with motorbike).
    Interesting. How long did it take you to true the rims by adjusting spoke tension? Must have cost quite a bit for the spoke threading tool when you lathed them up, right? (Ours was over $1200, for a widdly little thing that merely grooves a thred into the end of a spoke).. Was your bike a 2 stroke or a 4 stroke? Always preferred 2 for offroad myself; had an older one without a motorised powervalve, so it was either grunty but gutless at the top end (better for riding in the sand quarry nex tto the park; quieter), or flat as a pancake until about 5k, after which it only took a few hours to strip the rear tyre of its tread on the slag heaps where we rode..

    Yes i have taken the kettle apart to see how it works.
    So.. uh.. How does it work? You know.. the flicks-off-when-it-boils mechanism? Mighty handy for defrosting a fridge I might add, just set it to boil inside, lid off (with an extension lead) and shut the fridge door..

    [qutoe]Yes I was curious how rubber was made.[/quote]
    Howstuffworks is indeed a truly fascinating site

    Just don't post replys to my posts anymore, u sicken me.
    Good points to those on shaky ground usually have that effect, yes..

    Now, back OT - did you follow up Arjay's notion of using the designer? Youre allowed to read the generated code, you know! I'm sure a curious george such as yourself would be satisfied with reading it, knowing where it was if you ever needed it, and then getting on with some real work.. I know I was (thoguh I have to admit I did used to do my Java GridBagLayouts by hand, and I taught my uni lecturer how they worked. Really wish I'd spent the time chasing girls and using Netbeans tho )
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured