この記事は2020年08月31日に投稿しました。
目次
リンク
1. はじめに
こんにちは、iOSのエディタアプリPWEditorの開発者の二俣です。
今回は業務で使用しているC++/CLIで印刷する向きを設定する方法についてです。
2. C++/CLIで印刷する向きを設定する
C++/CLIで印刷する向きを設定するには、PageSettingsクラスのLandscapeプロパティを使用します。
Landscapeプロパティをtrueに設定すると横向き、falseに設定すると縦向きになります。
実装例
MainForm.h
#pragma once namespace CLIPrintLandscape { 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::Drawing::Printing; using namespace CLIPrintLandscape; /// <summary> /// MainForm の概要 /// </summary> public ref class MainForm : public System::Windows::Forms::Form { public: MainForm(void) { InitializeComponent(); // //TODO: ここにコンストラクター コードを追加します // } protected: /// <summary> /// 使用中のリソースをすべてクリーンアップします。 /// </summary> ~MainForm() { if (components) { delete components; } } private: System::Windows::Forms::Button^ PrintButton; protected: protected: private: /// <summary> /// 必要なデザイナー変数です。 /// </summary> System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code /// <summary> /// デザイナー サポートに必要なメソッドです。このメソッドの内容を /// コード エディターで変更しないでください。 /// </summary> void InitializeComponent(void) { this->PrintButton = (gcnew System::Windows::Forms::Button()); this->SuspendLayout(); // // PrintButton // this->PrintButton->Location = System::Drawing::Point(104, 16); this->PrintButton->Name = L"PrintButton"; this->PrintButton->Size = System::Drawing::Size(75, 23); this->PrintButton->TabIndex = 0; this->PrintButton->Text = L"印刷"; this->PrintButton->UseVisualStyleBackColor = true; this->PrintButton->Click += gcnew System::EventHandler(this, &MainForm::PrintButton_Click); // // MainForm // this->AutoScaleDimensions = System::Drawing::SizeF(6, 12); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(284, 56); this->Controls->Add(this->PrintButton); this->Name = L"MainForm"; this->Text = L"MainForm"; this->ResumeLayout(false); } #pragma endregion private: System::Void PrintButton_Click(System::Object^ sender, System::EventArgs^ e) { PrintDocument^ printDocument = gcnew PrintDocument(); PageSettings^ pageSettings = printDocument->DefaultPageSettings; // true:横向き/false:縦向き pageSettings->Landscape = true; } }; }
API Reference
PageSettingsクラス
[Landscape][Landscape]プロパティ
3. おわりに
横向きで印刷する必要があり、その方法を調べてみました。
リンク
紹介している一部の記事のコードはGitlabで公開しています。
興味のある方は覗いてみてください。
私が勤務しているニューラルでは、主に組み込み系ソフトの開発を行っております。
弊社製品のハイブリッドOS [Bi-OS][Bi-OS]は高い技術力を評価されており、特に制御系や通信系を得意としています。
私自身はiOSモバイルアプリやウィンドウズアプリを得意としております。
ソフトウェア開発に関して相談などございましたら、お気軽にご連絡ください。
また一緒に働きたい技術者の方も随時募集中です。
興味がありましたらご連絡ください。
EMAIL : info-nr@newral.co.jp / m-futamata@newral.co.jp
TEL : 042-523-3663
FAX : 042-540-1688