永利集团官网

首页 > 热门提问 > c#界面设计

c#界面设计

提问

问题
列表

  • C#怎么实现页面打印功能?有相应控件吗?代码怎么写?有例子更好,谢谢!

    查看答案>>

  • 用C#编写设计一个Windows应用程序,程序中定义一个学生类,

    查看答案>>

  • 求C#窗体程序工具箱各种控件的用处及各属性的用处

    查看答案>>

  • C# WPF界面设计,不同按钮显示不同的界面,需要新建多个页面吗?如何按各自的按钮显示各自的页面。

    查看答案>>

  • C#怎么通过控件名称找到窗口设计里对应的控件

    查看答案>>

  • C#如何通过一个按钮实现窗体界面的中英文切换?

    查看答案>>

  • 请教devexpress的winform界面开发基本步骤

    查看答案>>

  • 用vs2010做c#的窗口程序,新建了一个程序,这时候是有设计视图的(那个即时的窗体视图),

    查看答案>>

  • c#中两个数求和界面设计及程序编写

    查看答案>>

  • c++和c#哪个做界面更好?

    查看答案>>

C#怎么实现页面打印功能?有相应控件吗?代码怎么写?有例子更好,谢谢!

Winform里集成了几个打印控件:PrintPreviewDialog,PrintDocument,PrintDialog,PageSetupDialog,PrintPreviewControl,看书看资料会把人看晕,实际上打印核心控件只有一个,就是PrintDocument,PrintPreviewDialog也有点用,就是页面预览控件,真正开发中如果需要打印功能,一般会从网上Down现成的控件,如果要自己手动写,费时又费力,本着学习的态度,我们需要知道打印是怎么实现的,写两个比较常用的打印服务,一个是打印DataTable的,另一个是打印TextBox的。 示例一:以表格形式打印DataTable内的数据//定义全局变量count,储存当前打印的行数int count=0;//定义一个方法,接收一个DataTable类型参数及PrintDocument的PrintPage事件传入的参数e以方便操作private voidPrintTable(DataTable dt, System.Drawing.Printing.PrintPageEventArgse){ //取得对应的Graphics对象 Graphicsg = e.Graphics; //获得相关页面X坐标、Y坐标、打印区域宽度、长度 intx = e.PageSettings.Margins.Left; inty = e.PageSettings.Margins.Top; intwidth = e.PageSettings.PaperSize.Width -e.PageSettings.Margins.Left- e.PageSettings.Margins.Right; intheight = e.PageSettings.PaperSize.Height -e.PageSettings.Margins.Top -e.PageSettings.Margins.Bottom; //定义打印字体 Fontfont = new Font("宋体",15); //rowCount是除去打印过的行数后剩下的行数 introwCount = dt.Rows.Count-count; //maxPageRow是当前设置下该页面可以打印的最大行数 intmaxPageRow=height/(int)font.GetHeight(); //因为是表格,先画一条水平直线 g.DrawLine(newPen(Brushes.Black, 1), new Point(x, y), new Point(x +(dt.Columns.Count) * 135, y)); //再画出表格各列的列标题 for(int i = 0; i < dt.Columns.Count; i++) { stringhead = dt.Columns[i].ColumnName; g.DrawString(head,font, Brushes.Black, x + i * 135, y); } //画完标题,再画一条直线 g.DrawLine(newPen(Brushes.Black, 1), new Point(x, y + (int)font.GetHeight()), newPoint(x + (dt.Columns.Count) * 135, y +(int)font.GetHeight())); //判断,如果剩下的行数小于可打印的最大行数,则执行下列代码 if(maxPageRow >=rowCount) { //当前行数小于Table内总行数时,循环 while(count < dt.Rows.Count) { //内循环打印Table内行数据 intcolumnCount = 0; while(columnCount < dt.Columns.Count) { stringtemp = dt.Rows[count][columnCount].ToString(); //打印每个单元格内的数据 g.DrawString(temp,font, Brushes.Black, x + columnCount * 135, y + (count %maxPageRow) * (int)font.GetHeight() +(int)font.GetHeight()); //打印完一行后,继续打印一条直线 g.DrawLine(newPen(Brushes.Black, 1), new Point(x, y + (count % maxPageRow) *(int)font.GetHeight() + 2 * (int)font.GetHeight()), new Point(x +(dt.Columns.Count) * 135, y + (count % maxPageRow) *(int)font.GetHeight() + 2 * (int)font.GetHeight())); columnCount++; } count++; } //所有数据打印完毕后,打印垂直直线 for (int i = 0; i <= dt.Columns.Count; i++) { g.DrawLine(newPen(Brushes.Black), new Point(x + i * 135, y), new Point(x + i *135, y + rowCount * (int)font.GetHeight() +(int)font.GetHeight())); } } //判断,如果剩下的行数大于可打印的最大行数,则执行下列代码 else { do { //与上面类似,注意下面while的条件 intcolumnCount = 0; while(columnCount < dt.Columns.Count) { stringtemp = dt.Rows[count][columnCount].ToString(); //打印每个单元格 g.DrawString(temp,font, Brushes.Black, x + columnCount * 135, y + (count %maxPageRow) * (int)font.GetHeight() +(int)font.GetHeight()); //打印水平直线 g.DrawLine(newPen(Brushes.Black, 1), new Point(x, y + (count % maxPageRow) *(int)font.GetHeight() + 2 * (int)font.GetHeight()), new Point(x +(dt.Columns.Count)*135, y + (count % maxPageRow) *(int)font.GetHeight() + 2 * (int)font.GetHeight())); columnCount++; } count++; }while ((count % maxPageRow >0)); //打印垂直直线 for(int i = 0; i <= dt.Columns.Count;i++ ) { g.DrawLine(newPen(Brushes.Black), new Point(x + i * 135, y), new Point(x + i *135, y + height + (int)font.GetHeight())); } } //指定HasMorePages值,如果页面最大行数小于剩下的行数,则返回true(还有),否则返回false if(maxPageRow
7 有帮助 展开

用C#编写设计一个Windows应用程序,程序中定义一个学生类,

这些数据处理要与数据库配合才能更好的实现。
1 有帮助 展开

求C#窗体程序工具箱各种控件的用处及各属性的用处

打开VS,然后鼠标点击toolbox那里,再然后摁F1,就可以转到那个官方帮助手册了https://msdn.microsoft.com/en-us/library/2381cd09(v=vs.110).aspx
1 有帮助 展开

C# WPF界面设计,不同按钮显示不同的界面,需要新建多个页面吗?如何按各自的按钮显示各自的页面。

跳转不需要。你应该知道UserControl 再了解一下ContentControl控件就知道了。
3 有帮助 展开

C#怎么通过控件名称找到窗口设计里对应的控件

父控件.Controls["名字"]就可以找到注意一定要是直接父级如果要找嵌套的子控件,那么需要递归
0 有帮助 展开

C#如何通过一个按钮实现窗体界面的中英文切换?

一、窗体的国际化解决方案新建一个WinForm解决方案后,选择主窗体,右击查看属性,找到Localizable属性,将其置为True,然后找到Language属性,选择你需要切换的语言,比如英语(美国)、中文(简体,中国)等。此时根据实际情况设计该Language下的窗体样式及语言。 图1 Form的属性设置 图2 根据选择的语言,自动生成的资源文件二、使用CultureInfo类实现国际化解决方案CultureInfo 类包含区域性特定的信息,例如语言、国家/地区、日历以及区域性约定。  using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms;  namespace LocationForm {     static class Program     {         ///          /// 应用程序的主入口点。         ///          [STAThread]         static void Main()         {             Application.EnableVisualStyles();             Application.SetCompatibleTextRenderingDefault(false);             //System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");             System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CN");             Application.Run(new Form1());         }     } } 三:实现效果 官方参考文献:https://msdn.microsoft.com/zh-cn/library/h6270d0z.aspx另外您可能是需要动态切换语言的吧.接着往下看.在 Visual Studio 的设计视图中,如果在 Properties 窗口中改变了程序的默认界面语言(Language),我们会注意到无论是工程还是窗体对应的 .Designer.cs 文件都会有显著的改变。比如,我们创建一个叫 MyForm 的 form,并且添加一个叫 MyButton 的按钮。在改变窗体 Properties 中的 Language 属性之前, .Designer.cs 代码文件中的 InitializeComponent 方法的内容大致如下:private void InitializeComponent(){this.myButton = new System.Windows.Forms.Button();this.SuspendLayout();//// myButton//this.myButton.Location = new System.Drawing.Point(100, 200);this.myButton.Name = "myButton";this.myButton.Size = new System.Drawing.Size(75, 23);this.myButton.TabIndex = 0;this.myButton.Text = "My Button";this.myButton.UseVisualStyleBackColor = true;//// myForm//this.ClientSize = new System.Drawing.Size(292, 273);this.Controls.Add(this.myButton);this.Name = "MyForm";this.Text = "My Form";this.ResumeLayout(false);}而在改变了窗体 Properties 中的 Language 属性之后,工程中除了默认的 .resx 文件之外,还会自动添加一个 .zh-CHS.resx 文件(假设我们将 Language 改变为 Chinese (Simplified))。另外,.Designer.cs 文件中的 InitializeComponent 方法也会改变成:private void InitializeComponent(){System.ComponentModel.ComponentResourceManager resources= new System.ComponentModel.ComponentResourceManager(typeof(MyForm));this.myButton = new System.Windows.Forms.Button();this.SuspendLayout();//// myButton//this.myButton.AccessibleDescription = null;this.myButton.AccessibleName = null;resources.ApplyResources(this.myButton, "myButton");this.myButton.BackgroundImage = null;this.myButton.Font = null;this.myButton.Name = "myButton";this.myButton.UseVisualStyleBackColor = true;//// myForm//this.AccessibleDescription = null;this.AccessibleName = null;resources.ApplyResources(this, "$this");this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;this.BackgroundImage = null;this.Controls.Add(this.myButton);this.Font = null;this.Icon = null;this.Name = "myForm";this.ResumeLayout(false);}我们注意到改变 Language 属性之后,代码的主要变化有:ComponentResourceManager resources = new ComponentResourceManager(typeof(MyForm));resources.ApplyResources(this.myButton, "myButton"); resources.ApplyResources(this, "$this");另外,设置控件属性(比如显示文字 Text,控件大小 Size,显示位置 Location 等)的代码都没有了。也就是说设置控件属性的代码都是由 resources.ApplyResource 方法来完成的。那么在我们想改变 WinForm 程序的界面显示语言的时候,能不能直接调用 ApplyResources 方法呢?答案是肯定的。为 myButton 添加 Click 事件的事件处理函数:private void myButton_Click(object sender, EventArgs e){int currentLcid = Thread.CurrentThread.CurrentUICulture.LCID;currentLcid = (currentLcid == 2052) ? 1033 : 2052; // Changes the CurrentUICulture property before changing the resources that are loaded for the win-form.Thread.CurrentThread.CurrentUICulture = new CultureInfo(currentLcid); // Reapplies resources.ComponentResourceManager resources = new ComponentResourceManager(typeof(MyForm));resources.ApplyResources(myButton, "myButton");resources.ApplyResources(this, "$this");}
8 有帮助 展开

请教devexpress的winform界面开发基本步骤

安装好DevExpress后,开发DevExpress窗体应用的步骤如下:1)利用DevExpress提供的向导模板,建立DevExpress的Winform项目2)建立好项目后,可以看到DevExpress提供的各种窗体控件3)向窗体拖入一个命令按钮SimpleButton,将其Text属性修改“关闭”4)鼠标双击命令按钮,编写后台代码using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace DXApplication3 {     public partial class Form1 : DevExpress.XtraEditors.XtraForm     {         public Form1()         {             InitializeComponent();         }         private void simpleButton1_Click(object sender, EventArgs e)         {             // 关闭窗口             this.Close();         }     } }5)运行,显示DevExpress风格的窗体。单击“关闭”可以关闭窗口
0 有帮助 展开

用vs2010做c#的窗口程序,新建了一个程序,这时候是有设计视图的(那个即时的窗体视图),

打开窗体 就显示设计视图 如果没有可以点击视图--》设计器 或者shift+f7
0 有帮助 展开

c#中两个数求和界面设计及程序编写

拖三个Textbox和一个Button双击Button,在事件里面添加private void button1_Click(object sender, EventArgs e){   textBox3.Text = (Decimal.Parse(textBox1.Text) + Decimal.Parse(textBox2.Text)).ToString("G");}如满意请采纳,谢谢。
0 有帮助 展开

c++和c#哪个做界面更好?

  1. C++的代码错误容易引起安全问题,造成内存泄漏,运行出错。C#的代码错误容易引起性能问题。如果追求性能,用C++,如果追求安全,用C#。  2. C++的开发难度高,开发周期较长,但是运行效率高;C#的开发难度低,开发效率高,运行效率低;  3. C++注重实现功能,只要时间充裕,可以实现非常强大的功能;C#更加注重软件工程的应用,各种设计模式的使用,面向对象,是现代软件工程的思想体现。适合企业内高效的开发模式;  4. C++的MFC界面编程难度较高,美化界面需要大量代码的支持。C#的WPF的界面编程很简单,界面代码与程序代码分开,界面可使用可视化设计程序,如Expression Blend设计。  5. C++对串口,网络TCP,数据库方便的编程都支持,但是没有现成的完整类库调用,需要大量代码支持。 C#中这些都已经有类库,直接调用即可。代码量少很多。  6. C++打造界面像使用画笔画图,想怎么画就怎么画,结果取决于画家的功力;C#打造界面像使用Photoshop画图,不会画画的人也能画出一些精美图片来。
1 有帮助 展开
img

在线咨询

建站在线咨询

img

TOP