Symbol Mc1000 Text文本閱讀器整體代碼

using System;

using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO;
namespace text
{
?/// <summary>
?/// Form1 的摘要說明。
?/// </summary>
?public class Form1 : System.Windows.Forms.Form
?{
??private System.Windows.Forms.MainMenu mainMenu1;
??private System.Windows.Forms.MenuItem menuItem1;
??private System.Windows.Forms.MenuItem menuItem2;
??private System.Windows.Forms.MenuItem menuItem3;
??private System.Windows.Forms.MenuItem menuItem4;
??private System.Windows.Forms.OpenFileDialog openFileDialog1;
??private System.Windows.Forms.MenuItem menuItem5;
??private System.Windows.Forms.TextBox textBox1;
??public static string pathstr="";
??public static int curRowNo = 0;
??public static long? PageNum = 0;
??static ArrayList pageList = new ArrayList();
??static FileStream fs;
??static int maxPage = int.MaxValue;
??static int pageReadBytes = 700;
??private System.Windows.Forms.MenuItem menuItem6;
??private System.Windows.Forms.Panel panel1;
??private System.Windows.Forms.TextBox PN;
??private System.Windows.Forms.Label label1;
??????? static int pageChar = 300;
??public Form1()
??{
???//
???// Windows 窗體設計器支持所必需的
???//
???InitializeComponent();

???//
???// TODO: 在 InitializeComponent 調用后添加任何構造函數代碼
???//
??}
??/// <summary>
??/// 清理所有正在使用的資源。
??/// </summary>
??protected override void Dispose( bool disposing )
??{
???base.Dispose( disposing );
??}
??#region Windows 窗體設計器生成的代碼
??/// <summary>
??/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
??/// 此方法的內容。
??/// </summary>
??private void InitializeComponent()
??{
???this.mainMenu1 = new System.Windows.Forms.MainMenu();
???this.menuItem1 = new System.Windows.Forms.MenuItem();
???this.menuItem2 = new System.Windows.Forms.MenuItem();
???this.menuItem3 = new System.Windows.Forms.MenuItem();
???this.menuItem4 = new System.Windows.Forms.MenuItem();
???this.menuItem6 = new System.Windows.Forms.MenuItem();
???this.menuItem5 = new System.Windows.Forms.MenuItem();
???this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
???this.textBox1 = new System.Windows.Forms.TextBox();
???this.panel1 = new System.Windows.Forms.Panel();
???this.PN = new System.Windows.Forms.TextBox();
???this.label1 = new System.Windows.Forms.Label();
???//
???// mainMenu1
???//
???this.mainMenu1.MenuItems.Add(this.menuItem1);
???this.mainMenu1.MenuItems.Add(this.menuItem4);
???//
???// menuItem1
???//
???this.menuItem1.MenuItems.Add(this.menuItem2);
???this.menuItem1.MenuItems.Add(this.menuItem3);
???this.menuItem1.Text = "文件";
???//
???// menuItem2
???//
???this.menuItem2.Text = "打開";
???this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
???//
???// menuItem3
???//
???this.menuItem3.Text = "關閉";
???this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
???//
???// menuItem4
???//
???this.menuItem4.MenuItems.Add(this.menuItem6);
???this.menuItem4.MenuItems.Add(this.menuItem5);
???this.menuItem4.Text = "幫助";
???//
???// menuItem6
???//
???this.menuItem6.Text = "屬性";
???this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click);
???//
???// menuItem5
???//
???this.menuItem5.Text = "關于";
???this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
???//
???// textBox1
???//
???this.textBox1.Location = new System.Drawing.Point(0, 32);
???this.textBox1.Multiline = true;
???this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both;
???this.textBox1.Size = new System.Drawing.Size(232, 160);
???this.textBox1.Text = "";
???this.textBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox1_KeyDown);
???//
???// panel1
???//
???this.panel1.Controls.Add(this.label1);
???this.panel1.Controls.Add(this.PN);
???this.panel1.Location = new System.Drawing.Point(0, 24);
???this.panel1.Size = new System.Drawing.Size(240, 184);
???this.panel1.Visible = false;
???//
???// PN
???//
???this.PN.Font = new System.Drawing.Font("宋體", 15.75F, System.Drawing.FontStyle.Bold);
???this.PN.Location = new System.Drawing.Point(40, 40);
???this.PN.Size = new System.Drawing.Size(112, 31);
???this.PN.Text = "0";
???this.PN.KeyDown += new System.Windows.Forms.KeyEventHandler(this.PN_KeyDown);
???//
???// label1
???//
???this.label1.Font = new System.Drawing.Font("宋體", 24F, System.Drawing.FontStyle.Bold);
???this.label1.Location = new System.Drawing.Point(32, 96);
???this.label1.Size = new System.Drawing.Size(128, 32);
???this.label1.Text = "ENT跳轉";
???//
???// Form1
???//
???this.ClientSize = new System.Drawing.Size(490, 447);
???this.Controls.Add(this.panel1);
???this.Controls.Add(this.textBox1);
???this.Menu = this.mainMenu1;
???this.Text = "文本查看器";

??}
??#endregion

??/// <summary>
??/// 應用程序的主入口點。
??/// </summary>

??static void Main()
??{
???Application.Run(new Form1());
??}

??private void menuItem2_Click(object sender, System.EventArgs e)
??{

???openFileDialog1.Filter = "txt?? files?? (*.txt)|*.txt";
???openFileDialog1.FilterIndex = 2;
??
???if (openFileDialog1.ShowDialog() == DialogResult.OK)
???{
??
????pathstr = openFileDialog1.FileName;?
????//this.textBox1.Text = displaytext(curRowNo, pathstr);
????this.Text = "文本查看器" + "1/" + PageNum.ToString();
????if (fs != null) fs.Close();
????pageList.Clear();
????fs = File.Open(pathstr, FileMode.Open, FileAccess.Read);

????PageNum = fs.Length / pageReadBytes - 120;
????curRowNo = 0;
????string text = ReadRow(fs, curRowNo);
????if (text != null && text.Length > 0)
????{
?????this.textBox1.Text = text;
?????this.Text = "文本查看器" + (curRowNo + 1).ToString() + "/" + PageNum.ToString();
?????this.Refresh();
????}

?
???}
???this.textBox1.Focus();
??}
??private static string displaytext(int curRowNo,string pathstr)
??{string textstr;
???byte[] rowBytes;
???FileStream fs = File.Open(pathstr, FileMode.Open, FileAccess.Read);
???long fileLength = fs.Length;
???PageNum = fileLength / 150;
???rowBytes = ReadRows(fs, curRowNo);
???? textstr = Encoding.Default.GetString(rowBytes, 0, 150).Trim();??
???fs.Close();
???return textstr;
??}
??private static byte[] ReadRows(FileStream fs, int recno)
??{

???byte[] rowBytes = new byte[150];
???if (recno < 0) return rowBytes;
???int position = recno * 150;
???fs.Seek(position, SeekOrigin.Begin);
???fs.Read(rowBytes, 0, 150);
???return rowBytes;
??}
??private void menuItem3_Click(object sender, System.EventArgs e)
??{
???this.Close();
??}
?
??private void addtext(string pathstr)
??{
???try
???{
??
????StreamReader reader = new StreamReader(pathstr, System.Text.Encoding.Default);
???
????while (reader.Peek() > 0)
????{????
?????string oneLine = reader.ReadLine();?
?????this.textBox1.Text+=oneLine+"/r/n";
????}
????reader.Close();
???}
???catch
???{
????MessageBox.Show("打開請檢查格式!");

???}
??
??}

??private void menuItem5_Click(object sender, System.EventArgs e)
??{
???MessageBox.Show("小航簡單文本閱讀器,版權歸呂順所有!");
??}
??private static string ReadRow(FileStream fs, int pageNo)
??{

???string textstr ;
???byte[] rowBytes;
???int bytecount;
???long startPosition = fs.Position;

???for (int i = 0; i < pageList.Count; i++)
???{
????if (((PageInfo)pageList[i]).PageNo == pageNo)
????{
?????bytecount =((PageInfo)pageList[i]).ByteCount;
?????rowBytes = new byte[bytecount];
?????fs.Position = ((PageInfo)pageList[i]).StartPosition;
?????bytecount = fs.Read(rowBytes,0, bytecount);
?????fs.Position = startPosition;
?????textstr = Encoding.Default.GetString(rowBytes, 0, bytecount);???????????????????
?????return textstr;
????}
???}
???if (fs.Position >= fs.Length - 1) return "";
???
???rowBytes = new byte[pageReadBytes];
???bytecount = fs.Read(rowBytes, 0, pageReadBytes);
???if(bytecount == 0) return "";

???int iDbCharCount = 0;
???if(bytecount == pageReadBytes && rowBytes[pageReadBytes - 1] > 127)
???{
????for (int i = pageReadBytes - 1;i>=0;i--)
????{??
?????if(rowBytes[i] > 127)
??????iDbCharCount ++;
?????else
??????break;
????}
???}
???try
???{
????textstr = Encoding.Default.GetString(rowBytes, 0, bytecount - iDbCharCount );
???}
???catch
???{
????textstr = Encoding.Default.GetString(rowBytes, 0, bytecount- iDbCharCount - 1);
???}
???textstr = textstr.Substring(0, Math.Min(pageChar, textstr.Length));
???int textByteCount = Encoding.Default.GetBytes(textstr, 0, Math.Min(pageChar,textstr.Length) , rowBytes, 0);
???if(bytecount < pageReadBytes - 1)
????fs.Seek(0, SeekOrigin.End);
???else
????fs.Seek(textByteCount - bytecount, SeekOrigin.Current);

???pageList.Add(new PageInfo(pageNo, startPosition,textByteCount));
???return textstr;
??}
??private struct PageInfo
??{
???public PageInfo(int pageNo, long startPosition, int byteCount)
???{
????StartPosition = startPosition;
????ByteCount = byteCount;
????PageNo = pageNo;
???}
???public long StartPosition;
???public int ByteCount;
???public int PageNo;

??}
??private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
??{
???if(e.KeyCode==Keys.Left)
???{
????if (curRowNo >= 0)
????{
?????curRowNo--;
?????string text = ReadRow(fs, curRowNo);
?????if (text != null && text.Length > 0)
?????{
??????this.textBox1.Text = text;
??????this.Text = "文本查看器" + (curRowNo + 1).ToString() + "/" + PageNum.ToString();
??????this.Refresh();
?????}
????}
????else
????{
?????MessageBox.Show("已經是第一頁!");
??????this.textBox1.Focus();
????}
???}
???if(e.KeyCode==Keys.Right)
???{
????if (curRowNo <= maxPage)
????{
?????curRowNo++;
?????string text = ReadRow(fs, curRowNo);
?????if (text != null && text.Length > 0)
?????{
??????this.textBox1.Text = text;
??????this.Text = "文本查看器" + (curRowNo + 1).ToString() + "/" + PageNum.ToString();
??????this.Refresh();
?????}
?????else
?????{
??????maxPage = curRowNo-1;
??????PageNum = maxPage + 1;
?????}
????}
????else
????{
?????MessageBox.Show("已經是最后一頁!");
?????this.textBox1.Focus();
????}
???}
??}

??private void SelectPage_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
??{
??
??}

??private void PN_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
??{
???try
???{
??????? curRowNo=Convert.ToInt32(this.PN.Text);????
????curRowNo=curRowNo-1;
????if(e.KeyCode==Keys.Enter)
????{
?????string text = ReadRow(fs, curRowNo);
?????
??????this.textBox1.Text = text;
??????this.Text = "文本查看器" + (curRowNo + 1).ToString() + "/" + PageNum.ToString();
??????this.Refresh();?????
?????MessageBox.Show("哦了!");
?????this.panel1.Visible=false;
?????this.textBox1.Focus();
????}

???}
???catch
???{
???MessageBox.Show("大順啊,請輸入數字!謝謝");
???}
??}

??private void menuItem6_Click(object sender, System.EventArgs e)
??{
???this.panel1.Visible=true;
???this.PN.Focus();
??}
?}

}?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/389326.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/389326.shtml
英文地址,請注明出處:http://en.pswp.cn/news/389326.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

python生日悖論分析_生日悖論

python生日悖論分析If you have a group of people in a room, how many do you need to for it to be more likely than not, that two or more will have the same birthday?如果您在一個房間里有一群人&#xff0c;那么您需要多少個才能使兩個或兩個以上的人有相同的生日&a…

統計0-n數字中出現k的次數

/*** 統計0-n數字中出現k的次數&#xff0c;其中k范圍為0-9 */ public static int countOne(int k, int n) {if (k > n) {return 0;}int sum 0;int right 0;for (int i 0; n > 0; i) {int last n % 10;sum last * i * (int) Math.pow(10, i - 1);if (k 0) {sum - (…

房價預測 search Search 中對數據預處理的學習

對于缺失的數據&#xff1a; 我們對連續數值的特征做標準化&#xff08;standardization&#xff09;&#xff1a;設該特征在整個數據集上的均值為 μ &#xff0c;標準差為 σ 。那么&#xff0c;我們可以將該特征的每個值先減去 μ 再除以 σ 得到標準化后的每個特征值。對于…

3.6.1.非阻塞IO

本節講解什么是非阻塞IO&#xff0c;如何將文件描述符修改為非阻塞式 3.6.1.1、阻塞與非阻塞 &#xff08;1&#xff09;阻塞是指函數調用會被阻塞。本質是當前進程調用了函數&#xff0c;進入內核里面去后&#xff0c;因為當前進程的執行條件不滿足&#xff0c;內核無法里面完…

rstudio 管道符號_R中的管道指南

rstudio 管道符號R基礎知識 (R Fundamentals) Data analysis often involves many steps. A typical journey from raw data to results might involve filtering cases, transforming values, summarising data, and then running a statistical test. But how can we link al…

蒙特卡洛模擬預測股票_使用蒙特卡洛模擬來預測極端天氣事件

蒙特卡洛模擬預測股票In a previous article, I outlined the limitations of conventional time series models such as ARIMA when it comes to forecasting extreme temperature values, which in and of themselves are outliers in the time series.在上一篇文章中 &#…

iOS之UITraitCollection

UITraitCollection 為表征 size class 而生&#xff0c;用來區分設備。你可以在它身上獲取到足以區分所有設備的特征。 UITraitEnvironment 協議、UIContentContainer 協議 UIViewController 遵循了這兩個協議&#xff0c;用來監聽和設置 traitCollection 的變化。 protocol UI…

直方圖繪制與直方圖均衡化實現

一&#xff0c;直方圖的繪制 1.直方圖的概念&#xff1a; 在圖像處理中&#xff0c;經常用到直方圖&#xff0c;如顏色直方圖、灰度直方圖等。 圖像的灰度直方圖就描述了圖像中灰度分布情況&#xff0c;能夠很直觀的展示出圖像中各個灰度級所 占的多少。 圖像的灰度直方圖是灰…

eclipse警告與報錯的修復

1.關閉所有eclipse校驗 windows->perference->validation disable all 2.Access restriction: The constructor BASE64Decoder() is not API (restriction on required library C:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar) 在builde path 移除jre&#xff0c;再…

時間序列因果關系_分析具有因果關系的時間序列干預:貨幣波動

時間序列因果關系When examining a time series, it is quite common to have an intervention influence that series at a particular point.在檢查時間序列時&#xff0c;在特定時間點對該序列產生干預影響是很常見的。 Some examples of this could be:例如&#xff1a; …

微生物 研究_微生物監測如何工作,為何如此重要

微生物 研究Background背景 While a New York Subway station is bustling with swarms of businessmen, students, artists, and millions of other city-goers every day, its floors, railings, stairways, toilets, walls, kiosks, and benches are teeming with non-huma…

Linux shell 腳本SDK 打包實踐, 收集assets和apk, 上傳FTP

2019獨角獸企業重金招聘Python工程師標準>>> git config user.name "jenkins" git config user.email "jenkinsgerrit.XXX.net" cp $JENKINS_HOME/maven.properties $WORKSPACE cp $JENKINS_HOME/maven.properties $WORKSPACE/app cp $JENKINS_…

opencv:卷積涉及的基礎概念,Sobel邊緣檢測代碼實現及卷積填充模式

具體參考我的另一篇文章&#xff1a; opencv:卷積涉及的基礎概念&#xff0c;Sobel邊緣檢測代碼實現及Same&#xff08;相同&#xff09;填充與Vaild&#xff08;有效&#xff09;填充 這里是對這一篇文章的補充&#xff01; 卷積—三種填充模式 橙色部分為image, 藍色部分為…

怎么查這個文件在linux下的哪個目錄

因為要裝pl/sql所以要查找tnsnames.ora文件。。看看怎么查這個文件在linux下的哪個目錄 find / -name tnsnames.ora 查到&#xff1a; /opt/app/oracle/product/10.2/network/admin/tnsnames.ora/opt/app/oracle/product/10.2/network/admin/samples/tnsnames.ora 還可以用loca…

無法從套接字中獲取更多數據_數據科學中應引起更多關注的一個組成部分

無法從套接字中獲取更多數據介紹 (Introduction) Data science, machine learning, artificial intelligence, those terms are all over the news. They get everyone excited with the promises of automation, new savings or higher earnings, new features, markets or te…

web數據交互_通過體育運動使用定制的交互式Web應用程序數據科學探索任何數據...

web數據交互Most good data projects start with the analyst doing something to get a feel for the data that they are dealing with.大多數好的數據項目都是從分析師開始做一些事情&#xff0c;以便對他們正在處理的數據有所了解。 They might hack together a Jupyter n…

C# .net 對圖片操作

using System.Drawing;using System.Drawing.Drawing2D;using System.Drawing.Imaging;public class ImageHelper{/// <summary>/// 獲取圖片中的各幀/// </summary>/// <param name"pPath">圖片路徑</param>/// <param name"pSaveP…

數據類型之Integer與int

數據類型之Integer與int Java入門 基本數據類型 眾所周知&#xff0c;Java是面向對象的語言&#xff0c;一切皆對象。但是為了兼容人類根深蒂固的數據處理習慣&#xff0c;加快常規數據的處理速度&#xff0c;提供了9種基本數據類型&#xff0c;他們都不具備對象的特性&#xf…

PCA(主成分分析)思想及實現

PCA的概念&#xff1a; PCA是用來實現特征提取的。 特征提取的主要目的是為了排除信息量小的特征&#xff0c;減少計算量等。 簡單來說&#xff1a; 當數據含有多個特征的時候&#xff0c;選取主要的特征&#xff0c;排除次要特征或者不重要的特征。 比如說&#xff1a;我們要…