微信小程序 vant下拉菜单打印value值

微信小程序 vant下拉菜单打印value值,第1张

<van-dropdown-menu active-color="#ff7600">

      <van-dropdown-item value="{{ value1 }}" options="{{ option1 }}" bind:change="shuChange"/>

    </van-dropdown-menu>

shuChange: function (e) {

    consolelog(edetail);

  },

adapter写的有问题吧,我没用过自定义adapter,之前用arrayadapter就直接设置就可以了

//初始化Adapter

ArrayAdapter adapter = new ArrayAdapter<String>(getApplicationContext(),

androidRlayoutsimple_dropdown_item_1line, all_list);

//对自动补全控件设置绑定的Adapter

etsetAdapter(adapter);

你先用arrayAdapter试一下看看是不是adapter的问题。再答应一下看看cursor取数据取得有没有问题。

第一道我只写出一部分,窗口定义的那些就不写了~

using SystemTextRegularExpressions;

private void button1_Click(object sender, EventArgs e)

{

Regex Re = new Regex(@"^\d$");

if (thistextBox1Text != "" && thistextBox2Text != "")

if (ReMatch(thistextBox1Text)Success && ReMatch(thistextBox2Text)Success)

thistextBox3Text = (ConvertToInt32(thistextBox1Text) + ConvertToInt32(thistextBox2Text))ToString();

else

thistextBox3Text = "ER";

}

private void textBox1_TextChanged(object sender, EventArgs e)

{

if (thistextBox1Text != "" && thistextBox2Text != "")

thisbutton1Enabled = true;

else

thisbutton1Enabled = false;

}

private void textBox2_TextChanged(object sender, EventArgs e)

{

if (thistextBox1Text != "" && thistextBox2Text != "")

thisbutton1Enabled = true;

else

thisbutton1Enabled = false;

}

private void button2_Click(object sender, EventArgs e)

{

ApplicationExit();

}

}

第2道:

using System;

using SystemCollectionsGeneric;

using SystemComponentModel;

using SystemData;

using SystemDrawing;

using SystemText;

using SystemWindowsForms;

namespace p2

{

partial class Form1

{

/// <summary>

/// 必需的设计器变量。

/// </summary>

private SystemComponentModelIContainer components = null;

/// <summary>

/// 清理所有正在使用的资源。

/// </summary>

/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>

protected override void Dispose(bool disposing)

{

if (disposing && (components != null))

{

componentsDispose();

}

baseDispose(disposing);

}

#region Windows 窗体设计器生成的代码

/// <summary>

/// 设计器支持所需的方法 - 不要

/// 使用代码编辑器修改此方法的内容。

/// </summary>

private void InitializeComponent()

{

thismenuStrip1 = new SystemWindowsFormsMenuStrip();

thisfileToolStripMenuItem = new SystemWindowsFormsToolStripMenuItem();

thisshowToolStripMenuItem = new SystemWindowsFormsToolStripMenuItem();

thishideToolStripMenuItem = new SystemWindowsFormsToolStripMenuItem();

thismaximizedToolStripMenuItem = new SystemWindowsFormsToolStripMenuItem();

thisexitToolStripMenuItem = new SystemWindowsFormsToolStripMenuItem();

thishelpToolStripMenuItem = new SystemWindowsFormsToolStripMenuItem();

thisstatusStrip1 = new SystemWindowsFormsStatusStrip();

thistoolStripStatusLabel1 = new SystemWindowsFormsToolStripStatusLabel();

thismenuStrip1SuspendLayout();

thisstatusStrip1SuspendLayout();

thisSuspendLayout();

//

// menuStrip1

//

thismenuStrip1ItemsAddRange(new SystemWindowsFormsToolStripItem[] {

thisfileToolStripMenuItem,

thisexitToolStripMenuItem,

thishelpToolStripMenuItem});

thismenuStrip1Location = new SystemDrawingPoint(0, 0);

thismenuStrip1Name = "menuStrip1";

thismenuStrip1Size = new SystemDrawingSize(292, 24);

thismenuStrip1TabIndex = 0;

thismenuStrip1Text = "menuStrip1";

//

// fileToolStripMenuItem

//

thisfileToolStripMenuItemDropDownItemsAddRange(new SystemWindowsFormsToolStripItem[] {

thisshowToolStripMenuItem,

thishideToolStripMenuItem,

thismaximizedToolStripMenuItem});

thisfileToolStripMenuItemName = "fileToolStripMenuItem";

thisfileToolStripMenuItemSize = new SystemDrawingSize(41, 20);

thisfileToolStripMenuItemText = "File";

//

// showToolStripMenuItem

//

thisshowToolStripMenuItemName = "showToolStripMenuItem";

thisshowToolStripMenuItemShortcutKeys = ((SystemWindowsFormsKeys)((SystemWindowsFormsKeysControl |

SystemWindowsFormsKeysS)));

thisshowToolStripMenuItemSize = new SystemDrawingSize(152, 22);

thisshowToolStripMenuItemText = "Show";

thisshowToolStripMenuItemClick += new SystemEventHandler(thisshowToolStripMenuItem_Click);

//

// hideToolStripMenuItem

//

thishideToolStripMenuItemName = "hideToolStripMenuItem";

thishideToolStripMenuItemShortcutKeys = ((SystemWindowsFormsKeys)((SystemWindowsFormsKeysControl |

SystemWindowsFormsKeysH)));

thishideToolStripMenuItemSize = new SystemDrawingSize(152, 22);

thishideToolStripMenuItemText = "Hide";

thishideToolStripMenuItemClick += new SystemEventHandler(thishideToolStripMenuItem_Click);

//

// maximizedToolStripMenuItem

//

thismaximizedToolStripMenuItemName = "maximizedToolStripMenuItem";

thismaximizedToolStripMenuItemSize = new SystemDrawingSize(152, 22);

thismaximizedToolStripMenuItemText = "maximized ";

thismaximizedToolStripMenuItemClick += new SystemEventHandler(thismaximizedToolStripMenuItem_Click);

//

// exitToolStripMenuItem

//

thisexitToolStripMenuItemName = "exitToolStripMenuItem";

thisexitToolStripMenuItemSize = new SystemDrawingSize(41, 20);

thisexitToolStripMenuItemText = "Exit";

thisexitToolStripMenuItemClick += new SystemEventHandler(thisexitToolStripMenuItem_Click);

//

// helpToolStripMenuItem

//

thishelpToolStripMenuItemName = "helpToolStripMenuItem";

thishelpToolStripMenuItemSize = new SystemDrawingSize(41, 20);

thishelpToolStripMenuItemText = "Help";

//

// statusStrip1

//

thisstatusStrip1ItemsAddRange(new SystemWindowsFormsToolStripItem[] {

thistoolStripStatusLabel1});

thisstatusStrip1Location = new SystemDrawingPoint(0, 244);

thisstatusStrip1Name = "statusStrip1";

thisstatusStrip1Size = new SystemDrawingSize(292, 22);

thisstatusStrip1TabIndex = 1;

thisstatusStrip1Text = "statusStrip1";

//

// toolStripStatusLabel1

//

thistoolStripStatusLabel1Name = "toolStripStatusLabel1";

thistoolStripStatusLabel1Size = new SystemDrawingSize(41, 17);

thistoolStripStatusLabel1Text = "Label1";

//

// Form1

//

thisAutoScaleDimensions = new SystemDrawingSizeF(6F, 12F);

thisAutoScaleMode = SystemWindowsFormsAutoScaleModeFont;

thisClientSize = new SystemDrawingSize(292, 266);

thisControlsAdd(thisstatusStrip1);

thisControlsAdd(thismenuStrip1);

thisMainMenuStrip = thismenuStrip1;

thisName = "Form1";

thisText = "Form1";

thisClientSizeChanged += new SystemEventHandler(thisForm1_ClientSizeChanged);

thisLoad += new SystemEventHandler(thisForm1_Load);

thismenuStrip1ResumeLayout(false);

thismenuStrip1PerformLayout();

thisstatusStrip1ResumeLayout(false);

thisstatusStrip1PerformLayout();

thisResumeLayout(false);

thisPerformLayout();

}

#endregion

private SystemWindowsFormsMenuStrip menuStrip1;

private SystemWindowsFormsToolStripMenuItem fileToolStripMenuItem;

private SystemWindowsFormsToolStripMenuItem showToolStripMenuItem;

private SystemWindowsFormsToolStripMenuItem hideToolStripMenuItem;

private SystemWindowsFormsToolStripMenuItem maximizedToolStripMenuItem;

private SystemWindowsFormsToolStripMenuItem exitToolStripMenuItem;

private SystemWindowsFormsToolStripMenuItem helpToolStripMenuItem;

private SystemWindowsFormsStatusStrip statusStrip1;

private SystemWindowsFormsToolStripStatusLabel toolStripStatusLabel1;

private Form2 F = new Form2();

}

public Form1()

{

InitializeComponent();

}

private void exitToolStripMenuItem_Click(object sender, EventArgs e)

{

ApplicationExit();

}

private void Form1_Load(object sender, EventArgs e)

{

thistoolStripStatusLabel1Text = "(" + thisWidthToString() + "," + thisHeightToString() + ")";

}

private void Form1_ClientSizeChanged(object sender, EventArgs e)

{

thistoolStripStatusLabel1Text = "(" + thisWidthToString() + "," + thisHeightToString() + ")";

}

private void showToolStripMenuItem_Click(object sender, EventArgs e)

{

FShow();

}

private void hideToolStripMenuItem_Click(object sender, EventArgs e)

{

FHide();

}

private void maximizedToolStripMenuItem_Click(object sender, EventArgs e)

{

thisWindowState = FormWindowStateMaximized;

}

}

指针是c语言的概念,VB、VBNET没有指针,除了指针以外也很少有人能玩到你的编程深度,关键看不懂呢。

???就是子程序的名称,比如每次点击c后就自动调动相对应的子程序,如子程序是

Private Sub my_do ()

End Sub

相应的AddHandler cClick, AddressOf my_do

实际上是个委托

页面产生点击事件(例如button上bindtap的回调中)后才可调用,每次请求都会d出授权窗口,用户同意后返回userInfo。

每次通过该接口获取用户个人信息均需用户确认

    wxgetUserProfile({

            desc: '展示用户信息', // 声明获取用户个人信息后的用途

            success: ({userInfo:{nickName,avatarUrl}}) => {

            //  consolelog(res)

            //  nickName 用户昵称,avatarUrl 用户头像地址

              thissetData({

                nickName,

                avatarUrl,

                flag:false

              })

            }

        })

  <van-dropdown-menu>

    <van-dropdown-item value="{{ value1 }}" options="{{ option1 }}"  bind:change="onSwitch1Change"/>

    <van-dropdown-item value="{{ value2 }}" options="{{ option2 }}" bind:change="onSwitch2Change" />

  </van-dropdown-menu>

data:{

option2: [

      { text: '评论排序', value: 0},

      { text: '评论倒序', value: 1 }

    ],

    value1: 0,

    value2: 0

}

onSwitch1Change({ detail }) {

    thisdatapage=1;

    thissetData({

      value1:detail,

      value2:0

    });

    thisinit()

  },

  onSwitch2Change({ detail }) {

    thisdatapage=1;

    thissetData({

      value2:detail,

      value1:0

    });

    thisinit()

  },

 logout(){

    logout>

五子棋的代码:

#include<iostream>

#include<stdioh>

#include<stdlibh>

#include <timeh>

using namespace std;

const int N=15;                 //1515的棋盘

const char ChessBoardflag = ' ';          //棋盘标志

const char flag1='o';              //玩家1或电脑的棋子标志

const char flag2='X';              //玩家2的棋子标志

typedef struct Coordinate          //坐标类

int x;                         //代表行

int y;                         //代表列

}Coordinate;

class GoBang                    //五子棋类

{

public:

GoBang()                //初始化

{

InitChessBoard();

}

void Play()               //下棋

{

Coordinate Pos1;      // 玩家1或电脑

Coordinate Pos2;      //玩家2

int n = 0;

while (1)

{

int mode = ChoiceMode();

while (1)

{

if (mode == 1)       //电脑vs玩家

{

ComputerChess(Pos1,flag1);     // 电脑下棋

if (GetVictory(Pos1, 0, flag1) == 1)     //0表示电脑,真表示获胜

break;

PlayChess(Pos2, 2, flag2);     //玩家2下棋

if (GetVictory(Pos2, 2, flag2))     //2表示玩家2

break;

}

else            //玩家1vs玩家2

{

PlayChess(Pos1, 1, flag1);     // 玩家1下棋

if (GetVictory(Pos1, 1, flag1))      //1表示玩家1

break;

PlayChess(Pos2, 2, flag2);     //玩家2下棋

if (GetVictory(Pos2, 2, flag2))  //2表示玩家2

break;

}

}

cout << "再来一局" << endl;

cout << "y or n :";

char c = 'y';

cin >> c;

if (c == 'n')

break;

}     

}

protected:

int ChoiceMode()           //选择模式

{

int i = 0;

system("cls");        //系统调用,清屏

InitChessBoard();       //重新初始化棋盘

cout << "0、退出  1、电脑vs玩家  2、玩家vs玩家" << endl;

while (1)

{

cout << "请选择:";

cin >> i;

if (i == 0)         //选择0退出

exit(1);

if (i == 1 || i == 2)

return i;

cout << "输入不合法" << endl;

}

}

void InitChessBoard()      //初始化棋盘

{

for (int i = 0; i < N + 1; ++i)   

{

for (int j = 0; j < N + 1; ++j)

{

_ChessBoard[i][j] = ChessBoardflag;

}

}

}

void PrintChessBoard()    //打印棋盘,这个函数可以自己调整

{

system("cls");                //系统调用,清空屏幕

for (int i = 0; i < N+1; ++i)

{

for (int j = 0; j < N+1; ++j)

{

if (i == 0)                               //打印列数字

{

if (j!=0)

printf("%d  ", j);

else

printf("   ");

}

else if (j == 0)                //打印行数字

printf("%2d ", i);

else

{

if (i < N+1)

{

printf("%c |",_ChessBoard[i][j]);

}

}

}

cout << endl;

cout << "   ";

for (int m = 0; m < N; m++)

{

printf("--|");

}

cout << endl;

}

}

void PlayChess(Coordinate& pos, int player, int flag)       //玩家下棋

{

PrintChessBoard();         //打印棋盘

while (1)

{

printf("玩家%d输入坐标:", player);

cin >> posx >> posy;

if (JudgeValue(pos) == 1)          //坐标合法

break;

cout << "坐标不合法,重新输入" << endl;

}

_ChessBoard[posx][posy] = flag;

}

void ComputerChess(Coordinate& pos, char flag)       //电脑下棋

{

PrintChessBoard();         //打印棋盘

int x = 0;

int y = 0;

while (1)

{

x = (rand() % N) + 1;      //产生1~N的随机数

srand((unsigned int) time(NULL));

y = (rand() % N) + 1;     //产生1~N的随机数

srand((unsigned int) time(NULL));

if (_ChessBoard[x][y] == ChessBoardflag)      //如果这个位置是空的,也就是没有棋子

break;

}

posx = x;

posy = y;

_ChessBoard[posx][posy] = flag;

}

int JudgeValue(const Coordinate& pos)       //判断输入坐标是不是合法

{

if (posx > 0 && posx <= N&&posy > 0 && posy <= N)

{

if (_ChessBoard[posx][posy] == ChessBoardflag)

{

return 1;    //合法

}

}

return 0;        //非法

}

int JudgeVictory(Coordinate pos, char flag)           //判断有没有人胜负(底层判断)

{

int begin = 0;

int end = 0;

int begin1 = 0;

int end1 = 0;

//判断行是否满足条件

(posy - 4) > 0 begin = (posy - 4) : begin = 1;

(posy + 4) >N end = N : end = (posy + 4);

for (int i = posx, j = begin; j + 4 <= end; j++)

{

if (_ChessBoard[i][j] == flag&&_ChessBoard[i][j + 1] == flag&&

_ChessBoard[i][j + 2] == flag&&_ChessBoard[i][j + 3] == flag&&

_ChessBoard[i][j + 4] == flag)

return 1;

}

//判断列是否满足条件

(posx - 4) > 0 begin = (posx - 4) : begin = 1;

(posx + 4) > N end = N : end = (posx + 4);

for (int j = posy, i = begin; i + 4 <= end; i++)

{

if (_ChessBoard[i][j] == flag&&_ChessBoard[i + 1][j] == flag&&

_ChessBoard[i + 2][j] == flag&&_ChessBoard[i + 3][j] == flag&&

_ChessBoard[i + 4][j] == flag)

return 1;

}

int len = 0;

//判断主对角线是否满足条件

posx > posy len = posy - 1 : len = posx - 1;

if (len > 4)

len = 4;

begin = posx - len;       //横坐标的起始位置

begin1 = posy - len;      //纵坐标的起始位置

posx > posy len = (N - posx) : len = (N - posy);

if (len>4)

len = 4;

end = posx + len;       //横坐标的结束位置

end1 = posy + len;      //纵坐标的结束位置

for (int i = begin, j = begin1; (i + 4 <= end) && (j + 4 <= end1); ++i, ++j)

{

if (_ChessBoard[i][j] == flag&&_ChessBoard[i + 1][j + 1] == flag&&

_ChessBoard[i + 2][j + 2] == flag&&_ChessBoard[i + 3][j + 3] == flag&&

_ChessBoard[i + 4][j + 4] == flag)

return 1;

}

//判断副对角线是否满足条件

(posx - 1) >(N - posy) len = (N - posy) : len = posx - 1;

if (len > 4)

len = 4;

begin = posx - len;       //横坐标的起始位置

begin1 = posy + len;      //纵坐标的起始位置

(N - posx) > (posy - 1) len = (posy - 1) : len = (N - posx);

if (len>4)

len = 4;

end = posx + len;       //横坐标的结束位置

end1 = posy - len;      //纵坐标的结束位置

for (int i = begin, j = begin1; (i + 4 <= end) && (j - 4 >= end1); ++i, --j)

{

if (_ChessBoard[i][j] == flag&&_ChessBoard[i + 1][j - 1] == flag&&

_ChessBoard[i + 2][j - 2] == flag&&_ChessBoard[i + 3][j - 3] == flag&&

_ChessBoard[i + 4][j - 4] == flag)

return 1;

}

for (int i = 1; i < N + 1; ++i)           //棋盘有没有下满

{

for (int j =1; j < N + 1; ++j)

{

if (_ChessBoard[i][j] == ChessBoardflag)

return 0;                      //0表示棋盘没满

}

}

return -1;      //和棋

}

bool GetVictory(Coordinate& pos, int player, int flag)   //对JudgeVictory的一层封装,得到具体那个玩家获胜

{

int n = JudgeVictory(pos, flag);   //判断有没有人获胜

if (n != 0)                    //有人获胜,0表示没有人获胜

{

PrintChessBoard();

if (n == 1)                //有玩家赢棋

{

if (player == 0)     //0表示电脑获胜,1表示玩家1,2表示玩家2

printf("电脑获胜\n");

else

printf("恭喜玩家%d获胜\n", player);

}

else

printf("双方和棋\n");

return true;      //已经有人获胜

}

return false;   //没有人获胜

}

private:

char _ChessBoard[N+1][N+1];   

};

扩展资料:

设计思路

1、进行问题分析与设计,计划实现的功能为,开局选择人机或双人对战,确定之后比赛开始。

2、比赛结束后初始化棋盘,询问是否继续比赛或退出,后续可加入复盘、悔棋等功能。

3、整个过程中,涉及到了棋子和棋盘两种对象,同时要加上人机对弈时的AI对象,即涉及到三个对象。

登录

首页

学习

实践

活动

专区

工具

TVP

返回腾讯云官网

全栈程序员站长

551K 篇文章

关注

写字板(Windows程序设计)

2022-09-06 09:52:05阅读 1730

大家好,又见面了,我是你们的朋友全栈君。

前言

c# 正编译生成debug,exe等文件,同样也可以通过exe反编译生成相对应的文件,一劳永逸,任君选择(`・ω・´) (我们老师为了给我们看要求效果给了我们一个半成品exe,cv工程师上线了,真为所欲为)

问题描述

验证简易相册程序的实现(不需要写入报告)

设计一个类似Windows写字板的程序,使其具有以下功能:

提供基本的写字板功能,如文件的打开,保存,支持txt、rtf;

实现多格式的文本的编辑、修饰等,均有相应的菜单来控制,常用的菜单项配备相应的工具栏按钮(可参照Windows自带的写字板)

按需添加其他的代码,如窗口的布局等;

实现自定义的查找对话框,有能力的同学可进一步实现替换/全文替换等功能

状态栏中显示学生学号、姓名等信息,在窗口的标题中显示当前正在编辑的文件名

(可选)其他你觉得实用的功能:如支持word等

(可选)将其改造成MDI程序:父窗口中包含新建、窗口、帮助等菜单;在运行时,子窗口的菜单会与其合并,合理设置各菜单项的MergeIndex/MergeAction属性,使其符合我们的使用习惯;编程允许用户调整各自窗口间的布局关系(平铺、层叠等)等

先看效果

解决方法

richtextbox

用richtextbox是一个类似写字板的一个控件,能满足rtf,txt等格式,如果要满足doc文档,去百度MicrosoftOfficeInteropWorddll,下载并引用,打开保存代码如下(其中saveName为文件名)

/// <summary>

/// 打开文档 *** 作

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void 打开OToolStripMenuItem_Click(object sender, EventArgs e)

{

openFileDialog1InitialDirectory = "C:\\";

openFileDialog1Filter = "rtf 文件|rtf|txt 文件|txt|doc files|doc";

if (openFileDialog1ShowDialog() != DialogResultOK)

return;

saveName = openFileDialog1FileName;

if (openFileDialog1FilterIndex == 1)

richTextBox1LoadFile(saveName);

else if (openFileDialog1FilterIndex == 2)

richTextBox1LoadFile(saveName, RichTextBoxStreamTypePlainText);

else

OpenWord(saveName);

Text = saveName;

}

public void 父窗体打开Open(WritingBoard writingBoard)

{

writingBoardopenFileDialog1InitialDirectory = "C:\\";

writingBoardopenFileDialog1Filter = "rtf 文件|rtf|txt 文件|txt|doc files|doc";

if (writingBoardopenFileDialog1ShowDialog() != DialogResultOK)

return;

saveName = writingBoardopenFileDialog1FileName;

if (writingBoardopenFileDialog1FilterIndex == 1)

writingBoardrichTextBox1LoadFile(saveName);

else if (writingBoardopenFileDialog1FilterIndex == 2)

writingBoardrichTextBox1LoadFile(saveName, RichTextBoxStreamTypePlainText);

else

OpenWord(saveName);

writingBoardText = saveName;

return;

}

public void OpenWord(string fileName)

{

ApplicationClass applicationClass = new ApplicationClass();

Document document = null;

object obj = MissingValue;

object FileName = fileName;

object ReadOnly = false;

object Visible = true;

try

{

document = applicationClassDocumentsOpen(ref FileName, ref obj, ref ReadOnly, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref Visible, ref obj, ref obj, ref obj, ref obj);

documentActiveWindowSelectionWholeStory();

documentActiveWindowSelectionCopy();

richTextBox1Paste();

}

finally

{

documentClose(ref obj, ref obj, ref obj);

applicationClassQuit(ref obj, ref obj, ref obj);

}

}

/// <summary>

/// 保存 *** 作

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void 保存SToolStripMenuItem_Click(object sender, EventArgs e)

{

if (saveName != "")

{

richTextBox1SaveFile(saveName, RichTextBoxStreamTypeRichText);

}

else

{

saveFileDialog1Filter = "rtf files|rtf";

if (saveFileDialog1ShowDialog() == DialogResultOK)

{

saveName = saveFileDialog1FileName;

richTextBox1SaveFile(saveName, RichTextBoxStreamTypeRichText);

}

}

}

/// <summary>

/// 另存为 *** 作

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void 另存为AToolStripMenuItem_Click(object sender, EventArgs e)

{

saveFileDialog1FileName = saveNameSubstring(saveNameLastIndexOf('\\') + 1);

saveFileDialog1Filter = "rtf files|rtf|txt files|txt|doc files|doc";

saveFileDialog1AddExtension = true;

if (saveFileDialog1ShowDialog() != DialogResultOK)

return;

saveName = saveFileDialog1FileName;

if (saveFileDialog1FilterIndex == 1)

richTextBox1SaveFile(saveName, RichTextBoxStreamTypeRichText);

else if (saveFileDialog1FilterIndex == 2)

richTextBox1SaveFile(saveName, RichTextBoxStreamTypePlainText);

else

SaveAsWord(saveName);

}

public void SaveAsWord(string fileName)

{

ApplicationClass applicationClass = new ApplicationClass();

Document document = null;

object obj = MissingValue;

object FileName = fileName;

try

{

document = applicationClassDocumentsAdd(ref obj, ref obj, ref obj, ref obj);

documentActiveWindowSelectionWholeStory();

richTextBox1SelectAll();

ClipboardSetData(DataFormatsRtf, richTextBox1SelectedRtf);

documentActiveWindowSelectionPaste();

documentSaveAs(ref FileName, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj, ref obj);

}

finally

{

documentClose(ref obj, ref obj, ref obj);

applicationClassQuit(ref obj, ref obj, ref obj);

}

}

/// <summary>

/// 新建 *** 作

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void 新建NToolStripMenuItem_Click(object sender, EventArgs e)

{

richTextBox1Clear();

saveName = "";

}

复制

写字板 *** 作设置

其他一系列doc加粗,倾斜,下划线,左中右对齐,字体型号颜色,查找(大小写,全字,正逆),其实本质上来说都是对richtextbox的一些属性的修改,注意多用DropDownOpening,DropDownItemClicked等 *** 作代替Click,使代码更加精简高效

  这是一个MDI调整子窗体使用DropDownItemClicked的例子,高效优雅 = v =

private void 窗口WToolStripMenuItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)

{

string layout=eClickedItemText;

switch(layout)

{

case "水平平铺": LayoutMdi(MdiLayoutTileHorizontal);break;

case "垂直平铺": LayoutMdi(MdiLayoutTileVertical); break;

case "层叠": LayoutMdi(MdiLayoutCascade); break;

}

}

复制

MDI的使用,是为了让一个父窗体拥有许多个子窗体,进行更加简单有效的 *** 作

在父窗体new子窗体就行,记得一系列基本 *** 作,你也可以通过生成函数和属性进行快速高效设置

private void 新建ToolStripMenuItem_Click(object sender, EventArgs e)

{

WritingBoard writingBoard = new WritingBoard();

writingBoardTopLevel = false;

writingBoardMdiParent = this;

writingBoardShow();

}

private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)

{

WritingBoard writingBoard = new WritingBoard();

writingBoardTopLevel = false;

writingBoardMdiParent = this;

writingBoard父窗体打开Open(writingBoard);

writingBoardShow();

}

private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)

{

foreach (WritingBoard writingBoard in MdiChildren) writingBoardClose();

ApplicationExit();

}

private void 窗口WToolStripMenuItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)

{

string layout=eClickedItemText;

switch(layout)

{

case "水平平铺": LayoutMdi(MdiLayoutTileHorizontal);break;

case "垂直平铺": LayoutMdi(MdiLayoutTileVertical); break;

case "层叠": LayoutMdi(MdiLayoutCascade); break;

}

}

复制

源码附上

传送门,我设置了分支,这样我就可以把不同内容相同属性的代码放在一起了,同时也可以拥有不同的md可以阅读,对于git 的整理也是不错的(`・ω・´)

发布者:全栈程序员栈长,转载请注明出处:>

using System;

using SystemDrawing;

using SystemCollections;

using SystemComponentModel;

using SystemWindowsForms;

using SystemData;

using SystemIO;

namespace RichText

{

/// <summary>

/// Form1 的摘要说明。

/// </summary>

public class Form1 : SystemWindowsFormsForm

{

private SystemWindowsFormsMainMenu mainMenu1;

private SystemWindowsFormsMenuItem menuItem1;

private SystemWindowsFormsRichTextBox rtxContent;

private SystemWindowsFormsMenuItem menuItemOpen;

private SystemWindowsFormsMenuItem menuItemSave;

private SystemWindowsFormsToolBar tbrStatus;

private StreamReader sr;

private StreamWriter sw;

/// <summary>

/// 必需的设计器变量。

/// </summary>

private SystemComponentModelContainer components = null;

public Form1()

{

//

// Windows 窗体设计器支持所必需的

//

InitializeComponent();

//

// TODO: 在 InitializeComponent 调用后添加任何构造函数代码

//

}

/// <summary>

/// 清理所有正在使用的资源。

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

componentsDispose();

}

}

baseDispose( disposing );

}

#region Windows 窗体设计器生成的代码

/// <summary>

/// 设计器支持所需的方法 - 不要使用代码编辑器修改

/// 此方法的内容。

/// </summary>

private void InitializeComponent()

{

SystemResourcesResourceManager resources = new SystemResourcesResourceManager(typeof(Form1));

thisrtxContent = new SystemWindowsFormsRichTextBox();

thismainMenu1 = new SystemWindowsFormsMainMenu();

thismenuItem1 = new SystemWindowsFormsMenuItem();

thismenuItemOpen = new SystemWindowsFormsMenuItem();

thismenuItemSave = new SystemWindowsFormsMenuItem();

thistbrStatus = new SystemWindowsFormsToolBar();

thisSuspendLayout();

//

// rtxContent

//

thisrtxContentAnchor = ((SystemWindowsFormsAnchorStyles)((((SystemWindowsFormsAnchorStylesTop | SystemWindowsFormsAnchorStylesBottom)

| SystemWindowsFormsAnchorStylesLeft)

| SystemWindowsFormsAnchorStylesRight)));

thisrtxContentLocation = new SystemDrawingPoint(0, 0);

thisrtxContentName = "rtxContent";

thisrtxContentSize = new SystemDrawingSize(296, 272);

thisrtxContentTabIndex = 0;

thisrtxContentText = "";

//

// mainMenu1

//

thismainMenu1MenuItemsAddRange(new SystemWindowsFormsMenuItem[] {

thismenuItem1});

//

// menuItem1

//

thismenuItem1Index = 0;

thismenuItem1MenuItemsAddRange(new SystemWindowsFormsMenuItem[] {

thismenuItemOpen,

thismenuItemSave});

thismenuItem1Text = "&File";

//

// menuItemOpen

//

thismenuItemOpenIndex = 0;

thismenuItemOpenText = "&Open";

thismenuItemOpenClick += new SystemEventHandler(thismenuItemOpen_Click);

//

// menuItemSave

//

thismenuItemSaveIndex = 1;

thismenuItemSaveText = "&Save";

thismenuItemSaveClick += new SystemEventHandler(thismenuItemSave_Click);

//

// tbrStatus

//

thistbrStatusButtonSize = new SystemDrawingSize(16, 16);

thistbrStatusDock = SystemWindowsFormsDockStyleBottom;

thistbrStatusDropDownArrows = true;

thistbrStatusLocation = new SystemDrawingPoint(0, 244);

thistbrStatusName = "tbrStatus";

thistbrStatusShowToolTips = true;

thistbrStatusSize = new SystemDrawingSize(292, 22);

thistbrStatusTabIndex = 1;

//

// Form1

//

thisAutoScaleBaseSize = new SystemDrawingSize(6, 14);

thisClientSize = new SystemDrawingSize(292, 266);

thisControlsAdd(thistbrStatus);

thisControlsAdd(thisrtxContent);

thisIcon = ((SystemDrawingIcon)(resourcesGetObject("$thisIcon")));

thisMenu = thismainMenu1;

thisName = "Form1";

thisText = "Text";

thisResumeLayout(false);

}

#endregion

/// <summary>

/// 应用程序的主入口点。

/// </summary>

[STAThread]

static void Main()

{

ApplicationRun(new Form1());

}

private void menuItemOpen_Click(object sender, SystemEventArgs e)

{

OpenFileDialog openFileDialog1 = new OpenFileDialog();

openFileDialog1Filter = "txt files (txt)|txt";

openFileDialog1FilterIndex = 2 ;

openFileDialog1Title = "Select A File ";

if(openFileDialog1ShowDialog() == DialogResultOK)

{

sr = new StreamReader(openFileDialog1FileName);

thisrtxContentText = srReadToEnd();

srClose();

}

}

private void menuItemSave_Click(object sender, SystemEventArgs e)

{

SaveFileDialog saveFileDialog1 = new SaveFileDialog();

saveFileDialog1Filter = "txt files (txt)|txt";

saveFileDialog1Title = "Save A File";

if(saveFileDialog1ShowDialog() == DialogResultOK)

{

sw = new StreamWriter(saveFileDialog1FileName);

swWrite(thisrtxContentText);

swClose();

}

}

}

}

以上就是关于微信小程序 vant下拉菜单打印value值全部的内容,包括:微信小程序 vant下拉菜单打印value值、Android开发中autocompletetextview怎么不能自动显示、帮帮忙做2道C#的题目等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9810944.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-02
下一篇 2023-05-02

发表评论

登录后才能评论

评论列表(0条)

保存