Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changes from Version 1 of DflResizableDialog

Show
Ignore:
Author:
jcc7 (IP: 68.97.93.38)
Timestamp:
11/12/05 04:33:59 (19 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DflResizableDialog

    v0 v1  
     1= Resizable Dialog = 
     2 
     3''Part of'' DflCategory 
     4 
     5== Description == 
     6 
     7Demonstrates !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 
     17private import std.string; 
     18 
     19private import dfl.form, dfl.event, dfl.drawing, dfl.application; 
     20private import dfl.button, dfl.textbox, dfl.treeview; 
     21 
     22 
     23class ResizableForm: Form 
     24{ 
     25this() 
     26{ 
     27  text = "DflResizeTest"; 
     28 
     29  CreateControls(); 
     30} 
     31 
     32const int DEFAULT_LEFT          = 2; 
     33const int DEFAULT_TOP           = 2; 
     34 
     35const int DEFAULT_HEIGHT_ADJUST = 45; 
     36const int DEFAULT_WIDTH_ADJUST  = 10; 
     37const int DEFAULT_RIGHT         = 504; 
     38 
     39const int DEFAULT_BOTTOM        = 404; 
     40const int CHAPTREE_WIDTH        = 122; 
     41const int DEFAULT_BUTTON_HEIGHT = 25; 
     42 
     43const int DEFAULT_BUTTON_WIDTH  = ((CHAPTREE_WIDTH / 2) - 3); 
     44const int SEARCHBUTTON_HEIGHT   = DEFAULT_BUTTON_HEIGHT; 
     45const int BOOKSBUTTON_WIDTH     = DEFAULT_BUTTON_WIDTH; 
     46 
     47const int HELPBUTTON_WIDTH      = DEFAULT_BUTTON_WIDTH; 
     48const int HELPBUTTON_LEFT       = (DEFAULT_RIGHT  
     49                                  - (DEFAULT_BUTTON_WIDTH + 5)); 
     50const int SEARCHBUTTON_WIDTH    = DEFAULT_BUTTON_WIDTH; 
     51 
     52const int SEARCHBUTTON_LEFT     = (DEFAULT_BUTTON_WIDTH + 4); 
     53const int SEARCHWORDS_LEFT      = (CHAPTREE_WIDTH + 0); 
     54const int CHAPTREE_HEIGHT       = (DEFAULT_BOTTOM  
     55                                  - (DEFAULT_BUTTON_HEIGHT  
     56                                  + DEFAULT_HEIGHT_ADJUST)); 
     57 
     58const int CHAPTREE_TOP          = (DEFAULT_BUTTON_HEIGHT + 4); 
     59const int OPTIONSBUTTON_WIDTH   = 60; 
     60const int OPTIONSBUTTON_LEFT    = (DEFAULT_RIGHT  
     61                                  - (OPTIONSBUTTON_WIDTH  
     62                                  + DEFAULT_BUTTON_WIDTH + 8)); 
     63 
     64const int TEXTVIEWER_WIDTH      = (DEFAULT_RIGHT  
     65                                  - (CHAPTREE_WIDTH + 3)); 
     66const int SEARCHWORDS_WIDTH     = (DEFAULT_RIGHT  
     67                                  - (CHAPTREE_WIDTH  
     68                                  + OPTIONSBUTTON_WIDTH  
     69                                  + DEFAULT_BUTTON_WIDTH + 8)); 
     70 
     71private 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 
     128private 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 
     154private Button    booksButton; 
     155private Button    helpButton; 
     156private Button    optionsButton; 
     157private Button    searchButton; 
     158 
     159private TreeView  chapSelectorTree; 
     160private TextBox   searchWordsTextBox; 
     161 
     162private TextBox   viewerTextBox; 
     163} 
     164 
     165int 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 ||