⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.h

📁 Wrox.Ivor.Hortons.Beginning.Visual.C.Plus.Plus.2008 With sourcecode
💻 H
📖 第 1 页 / 共 5 页
字号:
#pragma once
/*
  For Exercise 18-3:
  You set the title bar text for the application by setting 
  the Text property for Form1.

  In the Form1 constructor I made the following changes:-
  -Initialized sketchFilepath to default file name.
  -InitializedDefaultExt and FileName properties for saveFileDialog.
  -Initialized Text property for Form1 to default file name.

  In the event handlers for the File/Save and File/Save As menu items
  I set the Text property for Form1 and called Invalidate() to redraw the form.
  In the File/Open event handler I also set the Text property for the form
  to be the value of the FileName property for the dialog after it closed
  and called Invalidate() to redraw the form.

  For Exercise 18-4:
  Clicking File/New should create a new empty document but before you replace
  the current document you must check whether it has been saved in its current
  state. To do this you need to keep track of the 'saved' status of the current sketch
  by ensuring that the Saved property for the sketch is set to false whenever the sketch
  is changed by adding deleting or moving elements.
  has the value true when the current sketch is new (empty) or has not been changed
  since it was last saved.
  To keep track of the sketch state, saving a file should set sketchSaved to true
  and changing a sketch by adding or deleting an element should set sketchSaved 
  to false.
  The File/New click handler should first check the Saved property for the sketch.
  If it is false a new empty sketch can replace the current sketch,
  otherwise the handler must prompt to allow the sketch to be saved before
  replacing it with a new empty sketch.
*/


#include "Elements.h"
#include "Sketch.h"
#include "PenDialog.h"
#include "TextDialog.h"

namespace CLRSketcher {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
  using namespace System::Runtime::Serialization::Formatters::Binary;
  using namespace System::IO;

  enum class ElementType {LINE, RECTANGLE, CIRCLE, CURVE, TEXT};
  enum class Mode {Normal, Move};
	/// <summary>
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
    Form1(void): elementType(ElementType::LINE), color(Color::Black)
      , drawing(false)
      , firstPoint(0), sketch(gcnew Sketch()), 
      highlightedElement(nullptr), mode(Mode::Normal)
      ,penDialog(gcnew PenDialog())
      , penWidth(1), textDialog(gcnew TextDialog())
      ,formatter(gcnew BinaryFormatter()), sketchFilepath(L"Sketch1")
    {
			InitializeComponent();
			//
			//TODO: Add the constructor code here
      penWidthComboBox->SelectedIndex = 0;
      textFont = Font;
      saveFileDialog->DefaultExt = L"ske";
      saveFileDialog->FileName = sketchFilepath;
      Text = L"CLR Sketcher: " + sketchFilepath;
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
  private: System::Windows::Forms::MenuStrip^  menuStrip1;
  protected: 
  private: System::Windows::Forms::ToolStripMenuItem^  fileToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  newToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  openToolStripMenuItem;
  private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator;
  private: System::Windows::Forms::ToolStripMenuItem^  saveToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  saveAsToolStripMenuItem;
  private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator1;
  private: System::Windows::Forms::ToolStripMenuItem^  printToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  printPreviewToolStripMenuItem;
  private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator2;
  private: System::Windows::Forms::ToolStripMenuItem^  exitToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  editToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  undoToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  redoToolStripMenuItem;
  private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator3;
  private: System::Windows::Forms::ToolStripMenuItem^  cutToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  copyToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  pasteToolStripMenuItem;
  private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator4;
  private: System::Windows::Forms::ToolStripMenuItem^  selectAllToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  toolsToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  customizeToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  optionsToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  elementToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  lineToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  rectangleToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  circleToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  curveToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  helpToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  contentsToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  indexToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  searchToolStripMenuItem;
  private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator5;
  private: System::Windows::Forms::ToolStripMenuItem^  aboutToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  colorToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  redToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  greenToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  blueToolStripMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  blackToolStripMenuItem;
  private: System::Windows::Forms::ToolStrip^  toolStrip1;
  private: System::Windows::Forms::ToolStripButton^  newToolStripButton;
  private: System::Windows::Forms::ToolStripButton^  openToolStripButton;
  private: System::Windows::Forms::ToolStripButton^  saveToolStripButton;
  private: System::Windows::Forms::ToolStripButton^  printToolStripButton;
  private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator6;

  private: System::Windows::Forms::ToolStripButton^  toolStripLineButton;
  private: System::Windows::Forms::ToolStripButton^  rectangleToolStripButton;
  private: System::Windows::Forms::ToolStripButton^  circleToolStripButton;
  private: System::Windows::Forms::ToolStripButton^  curveToolStripButton;
  private: System::Windows::Forms::ToolStripButton^  blackToolStripButton;
  private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator8;
  private: System::Windows::Forms::ToolStripButton^  redToolStripButton;
  private: System::Windows::Forms::ToolStripButton^  greenToolStripButton;
  private: System::Windows::Forms::ToolStripButton^  blueToolStripButton;
  private: System::Windows::Forms::ContextMenuStrip^  contextMenuStrip1;
  private: System::Windows::Forms::ToolStripMenuItem^  moveContextMenuItem;

  private: System::Windows::Forms::ToolStripMenuItem^  sendToBackContextMenuItem;
  private: System::Windows::Forms::ToolStripSeparator^  contextSeparator;

  private: System::Windows::Forms::ToolStripMenuItem^  lineContextMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  rectangleContextMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  circleContextMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  curveContextMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  blackContextMenuItem;

  private: System::Windows::Forms::ToolStripMenuItem^  redContextMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  greenContextMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  blueContextMenuItem;
  private: System::Windows::Forms::ToolStripMenuItem^  deleteContextMenuItem;
private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator9;
private: System::Windows::Forms::ToolStripButton^  penWidthButton;

private: System::Windows::Forms::ToolStripComboBox^  penWidthComboBox;
private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator10;
private: System::Windows::Forms::ToolStripMenuItem^  textToolStripMenuItem;
private: System::Windows::Forms::ToolStripButton^  textToolStripButton;

private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator7;
private: System::Windows::Forms::ToolStripButton^  fontToolStripButton;
private: System::Windows::Forms::FontDialog^  fontDialog1;
private: System::Windows::Forms::ToolStripMenuItem^  textContextMenuItem;
private: System::Windows::Forms::OpenFileDialog^  openFileDialog;
private: System::Windows::Forms::SaveFileDialog^  saveFileDialog;
private: System::Drawing::Printing::PrintDocument^  printDocument;
private: System::Windows::Forms::PrintDialog^  printDialog;

  private: System::ComponentModel::IContainer^  components;


	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>


#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
      this->components = (gcnew System::ComponentModel::Container());
      System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
      this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
      this->fileToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
      this->newToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
      this->openToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
      this->toolStripSeparator = (gcnew System::Windows::Forms::ToolStripSeparator());
      this->saveToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
      this->saveAsToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
      this->toolStripSeparator1 = (gcnew System::Windows::Forms::ToolStripSeparator());
      this->printToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
      this->printPreviewToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
      this->toolStripSeparator2 = (gcnew System::Windows::Forms::ToolStripSeparator());
      this->exitToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
      this->editToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
      this->undoToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
      this->redoToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
      this->toolStripSeparator3 = (gcnew System::Windows::Forms::ToolStripSeparator());
      this->cutToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
      this->copyToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
      this->pasteToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
      this->toolStripSeparator4 = (gcnew System::Windows::Forms::ToolStripSeparator());
      this->selectAllToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
      this->toolsToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
      this->customizeToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
      this->optionsToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -