| 1 | = Resizable Dialog = |
---|
| 2 | |
---|
| 3 | ''Part of'' DflCategory |
---|
| 4 | |
---|
| 5 | == Description == |
---|
| 6 | |
---|
| 7 | Demonstrates !DialogApp that adjusts the position and size of several controls when the overall application window is resized. (Caveat: Done by a DFL newbie so this may not be best way to accomplish the goal.) |
---|
| 8 | |
---|
| 9 | == Example == |
---|
| 10 | |
---|
| 11 | {{{ |
---|
| 12 | #!d |
---|
| 13 | // To compile: |
---|
| 14 | |
---|
| 15 | // dmd DflTest dfl.lib -L/exet:nt/su:windows:4.0 |
---|
| 16 | |
---|
| 17 | private import std.string; |
---|
| 18 | |
---|
| 19 | private import dfl.form, dfl.event, dfl.drawing, dfl.application; |
---|
| 20 | private import dfl.button, dfl.textbox, dfl.treeview; |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | class ResizableForm: Form |
---|
| 24 | { |
---|
| 25 | this() |
---|
| 26 | { |
---|
| 27 | text = "DflResizeTest"; |
---|
| 28 | |
---|
| 29 | CreateControls(); |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | const int DEFAULT_LEFT = 2; |
---|
| 33 | const int DEFAULT_TOP = 2; |
---|
| 34 | |
---|
| 35 | const int DEFAULT_HEIGHT_ADJUST = 45; |
---|
| 36 | const int DEFAULT_WIDTH_ADJUST = 10; |
---|
| 37 | const int DEFAULT_RIGHT = 504; |
---|
| 38 | |
---|
| 39 | const int DEFAULT_BOTTOM = 404; |
---|
| 40 | const int CHAPTREE_WIDTH = 122; |
---|
| 41 | const int DEFAULT_BUTTON_HEIGHT = 25; |
---|
| 42 | |
---|
| 43 | const int DEFAULT_BUTTON_WIDTH = ((CHAPTREE_WIDTH / 2) - 3); |
---|
| 44 | const int SEARCHBUTTON_HEIGHT = DEFAULT_BUTTON_HEIGHT; |
---|
| 45 | const int BOOKSBUTTON_WIDTH = DEFAULT_BUTTON_WIDTH; |
---|
| 46 | |
---|
| 47 | const int HELPBUTTON_WIDTH = DEFAULT_BUTTON_WIDTH; |
---|
| 48 | const int HELPBUTTON_LEFT = (DEFAULT_RIGHT |
---|
| 49 | - (DEFAULT_BUTTON_WIDTH + 5)); |
---|
| 50 | const int SEARCHBUTTON_WIDTH = DEFAULT_BUTTON_WIDTH; |
---|
| 51 | |
---|
| 52 | const int SEARCHBUTTON_LEFT = (DEFAULT_BUTTON_WIDTH + 4); |
---|
| 53 | const int SEARCHWORDS_LEFT = (CHAPTREE_WIDTH + 0); |
---|
| 54 | const int CHAPTREE_HEIGHT = (DEFAULT_BOTTOM |
---|
| 55 | - (DEFAULT_BUTTON_HEIGHT |
---|
| 56 | + DEFAULT_HEIGHT_ADJUST)); |
---|
| 57 | |
---|
| 58 | const int CHAPTREE_TOP = (DEFAULT_BUTTON_HEIGHT + 4); |
---|
| 59 | const int OPTIONSBUTTON_WIDTH = 60; |
---|
| 60 | const int OPTIONSBUTTON_LEFT = (DEFAULT_RIGHT |
---|
| 61 | - (OPTIONSBUTTON_WIDTH |
---|
| 62 | + DEFAULT_BUTTON_WIDTH + 8)); |
---|
| 63 | |
---|
| 64 | const int TEXTVIEWER_WIDTH = (DEFAULT_RIGHT |
---|
| 65 | - (CHAPTREE_WIDTH + 3)); |
---|
| 66 | const int SEARCHWORDS_WIDTH = (DEFAULT_RIGHT |
---|
| 67 | - (CHAPTREE_WIDTH |
---|
| 68 | + OPTIONSBUTTON_WIDTH |
---|
| 69 | + DEFAULT_BUTTON_WIDTH + 8)); |
---|
| 70 | |
---|
| 71 | private void CreateControls() |
---|
| 72 | { |
---|
| 73 | size = Size((DEFAULT_RIGHT - DEFAULT_LEFT) + DEFAULT_WIDTH_ADJUST, |
---|
| 74 | DEFAULT_BOTTOM - DEFAULT_TOP); // Overall form size |
---|
| 75 | |
---|
| 76 | resize ~= &ResizeForm; |
---|
| 77 | |
---|
| 78 | booksButton = new Button; |
---|
| 79 | booksButton.parent = this; |
---|
| 80 | booksButton.text = "Books"; |
---|
| 81 | booksButton.location = Point(DEFAULT_LEFT, DEFAULT_TOP); |
---|
| 82 | booksButton.size = Size(DEFAULT_BUTTON_WIDTH, |
---|
| 83 | DEFAULT_BUTTON_HEIGHT); |
---|
| 84 | |
---|
| 85 | helpButton = new Button; |
---|
| 86 | helpButton.parent = this; |
---|
| 87 | helpButton.text = "Help"; |
---|
| 88 | helpButton.size = Size(DEFAULT_BUTTON_WIDTH, |
---|
| 89 | DEFAULT_BUTTON_HEIGHT); |
---|
| 90 | |
---|
| 91 | optionsButton = new Button; |
---|
| 92 | optionsButton.parent = this; |
---|
| 93 | optionsButton.text = "Options"; |
---|
| 94 | optionsButton.size = Size(DEFAULT_BUTTON_WIDTH, |
---|
| 95 | DEFAULT_BUTTON_HEIGHT); |
---|
| 96 | |
---|
| 97 | searchButton = new Button; |
---|
| 98 | searchButton.parent = this; |
---|
| 99 | searchButton.text = "Search"; |
---|
| 100 | searchButton.location = Point(SEARCHBUTTON_LEFT, DEFAULT_TOP); |
---|
| 101 | searchButton.size = Size(DEFAULT_BUTTON_WIDTH, |
---|
| 102 | DEFAULT_BUTTON_HEIGHT); |
---|
| 103 | |
---|
| 104 | searchWordsTextBox = new TextBox; |
---|
| 105 | searchWordsTextBox.parent = this; |
---|
| 106 | searchWordsTextBox.text = "searchWordsTextBox"; |
---|
| 107 | searchWordsTextBox.location = Point(SEARCHWORDS_LEFT, |
---|
| 108 | DEFAULT_TOP); |
---|
| 109 | searchWordsTextBox.multiline = false; |
---|
| 110 | searchWordsTextBox.readOnly = false; |
---|
| 111 | |
---|
| 112 | viewerTextBox = new TextBox; |
---|
| 113 | viewerTextBox.parent = this; |
---|
| 114 | viewerTextBox.text = "viewerTextBox"; |
---|
| 115 | viewerTextBox.location = Point(CHAPTREE_WIDTH, CHAPTREE_TOP); |
---|
| 116 | viewerTextBox.multiline = true; |
---|
| 117 | viewerTextBox.readOnly = true; |
---|
| 118 | viewerTextBox.wordWrap = true; |
---|
| 119 | |
---|
| 120 | chapSelectorTree = new TreeView; |
---|
| 121 | chapSelectorTree.parent = this; |
---|
| 122 | chapSelectorTree.location = Point(DEFAULT_LEFT, CHAPTREE_TOP); |
---|
| 123 | |
---|
| 124 | ResizeForm(null, null); |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | private void ResizeForm(Object sender, EventArgs ea) |
---|
| 129 | { |
---|
| 130 | Size formClientSize = clientSize(); |
---|
| 131 | Rect formBounds = bounds(); |
---|
| 132 | int formHeight = formClientSize.height; |
---|
| 133 | int formWidth = formClientSize.width; |
---|
| 134 | |
---|
| 135 | int helpButtonLeft = (formWidth - (DEFAULT_BUTTON_WIDTH + 5)); |
---|
| 136 | int chapTreeHeight = (formHeight - (DEFAULT_BUTTON_HEIGHT + 10)); |
---|
| 137 | int optionsButtonLeft = (formWidth - (OPTIONSBUTTON_WIDTH |
---|
| 138 | + DEFAULT_BUTTON_WIDTH + 8)); |
---|
| 139 | int textViewerWidth = (formWidth - (CHAPTREE_WIDTH + 3)); |
---|
| 140 | int searchWordsWidth = (formWidth - (CHAPTREE_WIDTH |
---|
| 141 | + OPTIONSBUTTON_WIDTH |
---|
| 142 | + DEFAULT_BUTTON_WIDTH + 8)); |
---|
| 143 | |
---|
| 144 | searchWordsTextBox.size = Size(searchWordsWidth, |
---|
| 145 | DEFAULT_BUTTON_HEIGHT); |
---|
| 146 | viewerTextBox.size = Size(textViewerWidth, chapTreeHeight); |
---|
| 147 | chapSelectorTree.size = Size(CHAPTREE_WIDTH, chapTreeHeight); |
---|
| 148 | |
---|
| 149 | optionsButton.location = Point(optionsButtonLeft, DEFAULT_TOP); |
---|
| 150 | helpButton.location = Point(helpButtonLeft, DEFAULT_TOP); |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | |
---|
| 154 | private Button booksButton; |
---|
| 155 | private Button helpButton; |
---|
| 156 | private Button optionsButton; |
---|
| 157 | private Button searchButton; |
---|
| 158 | |
---|
| 159 | private TreeView chapSelectorTree; |
---|
| 160 | private TextBox searchWordsTextBox; |
---|
| 161 | |
---|
| 162 | private TextBox viewerTextBox; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | int main() |
---|
| 166 | { |
---|
| 167 | Application.run(new ResizableForm); |
---|
| 168 | |
---|
| 169 | return 0; |
---|
| 170 | } |
---|
| 171 | }}} |
---|
| 172 | |
---|
| 173 | == Source == |
---|
| 174 | |
---|
| 175 | || Link || http://www.dsource.org/tutorials/index.php?show_example=136 || |
---|
| 176 | || Posted by || Lynn || |
---|
| 177 | || Date/Time || Wed Dec 22, 2004 4:04 pm || |