示例#1
0
		public void SetupFormFields( DynForm f )
		{
			// Create lists with available items
			// For convenience I do it here, but this data can come from anywhere if needed
			var allPets = new List<DynFormList>();
			allPets.Add( new DynFormList( "DogID", "Dog" ) );
			allPets.Add( new DynFormList( "CatID", "Cat" ) );
			allPets.Add( new DynFormList( "RatID", "Rat" ) );
			allPets.Add( new DynFormList( "LizardID", "Lizard" ) );
			allPets.Add( new DynFormList( "BirdID", "Bird" ) );
			allPets.Add( new DynFormList( "FishID", "Fish" ) );
			allPets.Add( new DynFormList( "RabbitID", "Rabbit" ) );
			allPets.Add( new DynFormList( "GremlinID", "Gremlin" ) );
			
			var allCages = new List<DynFormList>();
			allCages.Add( new DynFormList( "Cage0", "Unknown" ) );
			allCages.Add( new DynFormList( "Cage1", "Small Cage" ) );
			allCages.Add( new DynFormList( "Cage2", "Medium Cage" ) );
			allCages.Add( new DynFormList( "Cage3", "Large Cage" ) );
			allCages.Add( new DynFormList( "Cage4", "Aquarium" ) );


			// Add controls to edit in the DynForm
			f.AddLayoutValueDataGrid( "Pets in Stock", "PetsInStock", "Pet", "Left (F2 to edit)", allPets, "Add Pet", "0" );
			f.AddLayoutDropdownDataGrid( "Cage Type", "CageTypes", allCages, "Pet", "Cage" );
			f.AddLayoutCheckboxDataGrid( "Feeding time", "FeedingTime", "Pet", "Do not feed after midnight" );
		}
示例#2
0
		// Button 1
		private void buttonNewPerson_Click( object sender, EventArgs e )
		{
			// This example creates a new Person object and opens a DynForm to edit it

			Person newPerson = new Person();
			var f = new DynForm( "New Person", newPerson );
			f.ShowDialog();

			// bSaveData indicates what button the user pressed (Save or Cancel)
			if( newPerson.bSaveData )
			{
				// Print the result to the console
				string pets = "";
				foreach( var pet in newPerson.Pets ) pets += pet.Text + " / ";
				Console.WriteLine(
					String.Format( "SSN: {0}\r\nName: {1}\r\nBirthday: {2}\r\nLucky Number: {3}\r\nFavorite Color: {4}\r\nLikes Pizza: {5}\r\nPets: {6}",
					newPerson.SSN,
					newPerson.Name,
					newPerson.Birthday.ToLongDateString(),
					newPerson.LuckyNumber,
					newPerson.FavoriteColor,
					newPerson.LikesPizza ? "Yes" : "No",
					pets
					));		
			}
			else
			{
				Console.WriteLine("User clicked cancel...");
			}
		}
示例#3
0
文件: Person.cs 项目: rlv-dan/DynForm
		public void SetupFormFields( DynForm f )
		{
			// This is where we "design" the form to be displayed.
			// Most follow this format: f.AddSomething( "Label", "PropertyName" )
			
			// It's usually a good thing to begin by adding a header
			f.AddLayoutHeader( "Person Details" );

			// If we are creating a new person we let the user set the SSN, but when editing an 
			// existing persons we just display the SSN in a label, since you are not allowed 
			// to change your SSN.
			if( this.SSN == "" )
				f.AddLayoutMaskedTextBox( "Social Security Number", "SSN", "000-00-0000" );	// See MSDN for info on setting up the MaskedTextBox validation pattern
			else
				f.AddLayoutLabel( "Social Security Number", "SSN" );

			// Name is a simple text input box
			f.AddLayoutTextBox( "Full name", "Name", 32 );

			// Dates can be set using a date picker
			f.AddLayoutDatePicker( "Date of bith", "Birthday" );

			// New header. Separate the form into logical section for improved usability
			f.AddLayoutHeader( "Trivia" );

			// The dropdown list needs some data to work with. This data can be created on the fly, like here, or obtained from any other data source you with
			var colors = new List<DynFormList>();
			colors.Add( new DynFormList( null, "Not set" ) );
			colors.Add( new DynFormList("Red","Red like roses") );
			colors.Add( new DynFormList( "Green", "Green like a summer field" ) );
			colors.Add( new DynFormList( "Blue", "Blue like the deep ocean" ) );
			f.AddLayoutDropdown("Favourite colour", "FavoriteColor", colors);

			// Number spinner. The last arguments allows you to set number of decimals and min/max values
			f.AddLayoutNumberBox( "Lucky Number", "LuckyNumber", 0, 1, 16 );

			// A simple checkbox working against a boolean
			f.AddLayoutCheckbox( "Likes pizza?", "LikesPizza" );

			// The listbox allows you to select items from a list.
			// Again, we use the DynFormList to provide DynForm with source data (allPets)
			var allPets = new List<DynFormList>();
			allPets.Add( new DynFormList( "DogID", "Dog" ) );
			allPets.Add( new DynFormList( "CatID", "Cat" ) );
			allPets.Add( new DynFormList( "RatID", "Rat" ) );
			allPets.Add( new DynFormList( "LizardID", "Lizard" ) );
			allPets.Add( new DynFormList( "BirdID", "Bird" ) );
			allPets.Add( new DynFormList( "FishID", "Fish" ) );
			allPets.Add( new DynFormList( "RabbitID", "Rabbit" ) );
			f.AddLayoutListbox( "Pets", "Pets", allPets, "Add a pet" );
		}
示例#4
0
		// Button 2
		private void buttonEditPerson_Click( object sender, EventArgs e )
		{
			// This example shows hows to edit an already existing object. This it is slightly 
			// more complicated due to the fact that the object sent to DynForm is always modified,
			// even if the user pressed cancel. Thus we need to work with a copy of the data to 
			// make sure to preserve the original data.

			// This is the source object being edited
			Person originalPerson = new Person() { SSN = "123-45-6789", Name = "Lois Lane", Birthday = new DateTime(1938,06,01), LuckyNumber = 7, LikesPizza = true, FavoriteColor = "Blue" };
			// Create a copy of the source object
			Person copyPerson = new Person() { SSN = originalPerson.SSN, Name = originalPerson.Name, Birthday = originalPerson.Birthday, LuckyNumber = originalPerson.LuckyNumber, LikesPizza = originalPerson.LikesPizza, FavoriteColor = originalPerson.FavoriteColor };
			// Open DynForm to edit the copy
			var f = new DynForm( "New Person", copyPerson );
			f.ShowDialog();

			// Only update the source object if the user pressed Save
			string output = "";
			if( copyPerson.bSaveData )
			{
				originalPerson = copyPerson;
				output += "Updating the original object!\r\n\r\n";
			}
			else
			{
				output += "User clicked cancel, keeping original object...\r\n\r\n";
			}

			// Print the result to the console
			string pets = "";
			foreach( var pet in originalPerson.Pets ) pets += pet.Text + " / ";
			output += String.Format( "SSN: {0}\r\nName: {1}\r\nBirthday: {2}\r\nLucky Number: {3}\r\nFavorite Color: {4}\r\nLikes Pizza: {5}\r\nPets: {6}",
				originalPerson.SSN,
				originalPerson.Name,
				originalPerson.Birthday.ToLongDateString(),
				originalPerson.LuckyNumber,
				originalPerson.FavoriteColor,
				originalPerson.LikesPizza ? "Yes" : "No",
				pets
				);
			Console.WriteLine( output );
		}
示例#5
0
		// Button 3
		private void buttonPetStore_Click( object sender, EventArgs e )
		{
			// This example shows how to work with more advanced data structures.
			// Go to the PetStore class to read more.
			PetStore petStore = new PetStore();
			var f = new DynForm( "Petstore Inventory", petStore );
			f.ShowDialog();
		}