Well set the text properties to new and delete once

Info icon This preview shows pages 828–831. Sign up to view the full content.

View Full Document Right Arrow Icon
We’ll set the Text properties to &New and &Delete , once more taking care to keep access keys unique. Again, we want all our controls to have sensible names, so we’ll go with titleText , dueDatePicker , descriptionText , newButton , and deleteButton for the vari- ous controls we’ve just added. (The names of the Label controls are not so significant, as we won’t be using them from the code behind, but out of a slightly obsessive sense of neatness we’ll called those titleLabel , dueDateLabel , and descriptionLabel .) Fig- ure 22-6 shows the work in progress. Figure 22-6. The basic layout In fact, we’re not quite done here because there’s a problem when the user resizes the form. As Figure 22-7 shows, the ListView fills all the width, but the remaining controls have somewhat disappointing behavior. Fortunately, we can fix this. 804 | Chapter 22: Windows Forms
Image of page 828

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Figure 22-7. Poor resize behavior Docking and Anchoring Windows Forms controls support a couple of kinds of automatic resizing behavior. They can be docked —we already have two docked controls, in fact. The SplitCon tainer is docked to fill the entire form, and the ListView is docked to fill the top half of the SplitContainer . If you edit the Dock property with the Properties window (instead of the Task pop up we used earlier) you can also dock controls to a particular edge of their container, rather than having to fill the whole thing—this is useful for menus and toolbars that need to appear along the top edge of a window. The other form of automatic resizing is anchoring . An anchored control doesn’t have to fill the whole width and/or height of its container, but instead can resize or move as its container resizes. You can anchor the top, left, bottom, or right of any control to the corresponding edge of its container. In fact, by default, controls are anchored to the top and left sides of their container—this means that when the container (e.g., the window) moves, the contained controls go with it, but if the user resizes the window by moving either the right or bottom edge, the controls remain as they are. Controls | 805
Image of page 829
We can exploit this to make our controls resize. The Title text box and the date picker should both be anchored to the top, left, and right, as shown in Figure 22-8 . So as the window changes width, the righthand edge of these controls will follow its righthand edge. The Description text box should be anchored on all four sides, so it resizes both vertically and horizontally. Figure 22-8. Anchoring to the left, top, and right The two buttons should be anchored only on the bottom and right, meaning you need to unanchor them from the top and left. That’s because we want them to follow the bottom-right corner of the window, but not to resize. With these changes in place, the user interface will now resize gracefully as the user resizes the window or adjusts the splitter. Good though that looks, our application doesn’t do anything yet. So the next step will be to hook up the controls to the data.
Image of page 830

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 831
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern