当前位置: 首页 > news >正文

电子商务网站建设与管理课程的目的泰安网络推广培训

电子商务网站建设与管理课程的目的,泰安网络推广培训,公司是做网站建设的怎么开票,app开发公司的管理机制背景:最近在项目中有需求需要在DataGridView中添加“删除”、“修改”按钮,用来对数据的操作以及显示。 在DataGridView中显示需要的按钮 首先在DataGridView中添加需要的列,此列是用来存放按钮的。 然后在代码中“画”按钮。 if (e.Column…

背景:最近在项目中有需求需要在DataGridView中添加“删除”、“修改”按钮,用来对数据的操作以及显示。

在DataGridView中显示需要的按钮

 首先在DataGridView中添加需要的列,此列是用来存放按钮的。

然后在代码中“画”按钮。

if (e.ColumnIndex >= 0 && e.RowIndex >= 0){if (this.dgvwProdCode.Columns[e.ColumnIndex].Name == "act"){StringFormat sf = StringFormat.GenericDefault.Clone() as StringFormat;//设置重绘入单元格的字体样式sf.FormatFlags = StringFormatFlags.DisplayFormatControl;sf.Alignment = StringAlignment.Center;sf.LineAlignment = StringAlignment.Center;sf.Trimming = StringTrimming.EllipsisCharacter;e.PaintBackground(e.CellBounds, true);//重绘边框//设置要写入字体的大小System.Drawing.Font myFont = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));SizeF sizeDel = e.Graphics.MeasureString("删除", myFont);SizeF sizeMod = e.Graphics.MeasureString("修改", myFont);SizeF sizeIsEnable = e.Graphics.MeasureString("启用/禁用", myFont);float fDel = sizeDel.Width / (sizeDel.Width + sizeMod.Width + sizeIsEnable.Width); //float fMod = sizeMod.Width / (sizeDel.Width + sizeMod.Width + sizeIsEnable.Width);float fIsEnable = sizeIsEnable.Width / (sizeDel.Width + sizeMod.Width+ sizeIsEnable.Width);//设置每个“按钮的边界”RectangleF rectDel = new RectangleF(e.CellBounds.Left, e.CellBounds.Top, e.CellBounds.Width * fDel, e.CellBounds.Height);RectangleF rectMod = new RectangleF(rectDel.Right, e.CellBounds.Top, e.CellBounds.Width * fMod, e.CellBounds.Height);RectangleF rectIsEnable = new RectangleF(rectMod.Right, e.CellBounds.Top, e.CellBounds.Width* fIsEnable, e.CellBounds.Height);e.Graphics.DrawString("删除", myFont, Brushes.Black, rectDel, sf); //绘制“按钮”e.Graphics.DrawString("修改", myFont, Brushes.Black, rectMod, sf);e.Graphics.DrawString("启用/禁用", myFont, Brushes.Black, rectIsEnable, sf);e.Handled = true;}}

以上代码是在DataGridView中可以显示需要的按钮。

给DataGridView添加事件,可以通过按钮来操作数据库

使用CellMouseClick方法来去执行事件。

 private void dgvwProdCode_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e){if (e.ColumnIndex >= 0 && e.RowIndex >= 0){Point curPosition = e.Location;//当前鼠标在当前单元格中的坐标if (this.dgvwProdCode.Columns[e.ColumnIndex].Name == "act"){Graphics g = this.dgvwProdCode.CreateGraphics();System.Drawing.Font myFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(134)));SizeF sizeDel = g.MeasureString("删除", myFont);SizeF sizeMod = g.MeasureString("修改", myFont);SizeF sizeIsEnable = g.MeasureString("启用/禁用", myFont);float fDel = sizeDel.Width / (sizeDel.Width + sizeMod.Width + sizeIsEnable.Width);float fMod = sizeMod.Width / (sizeDel.Width + sizeMod.Width + sizeIsEnable.Width);float fIsEnable = sizeIsEnable.Width / (sizeDel.Width + sizeMod.Width + sizeIsEnable.Width);Rectangle rectTotal = new Rectangle(0, 0, this.dgvwProdCode.Columns[e.ColumnIndex].Width, this.dgvwProdCode.Rows[e.RowIndex].Height);RectangleF rectDel = new RectangleF(rectTotal.Left, rectTotal.Top, rectTotal.Width * fDel, rectTotal.Height);RectangleF rectMod = new RectangleF(rectDel.Right, rectTotal.Top, rectTotal.Width * fMod, rectTotal.Height);RectangleF rectIsEnable = new RectangleF(rectMod.Right, rectTotal.Top, rectTotal.Width * fIsEnable, rectTotal.Height);//判断当前鼠标在哪个“按钮”范围内if (rectDel.Contains(curPosition))//删除{IProduct product = new ProductImpl();ProductInfoEntity productInfo = new ProductInfoEntity();productInfo.recipe = dgvwProdCode.Rows[e.RowIndex].Cells[1].Value.ToString();if (product.Delete(productInfo) > 0){this.dgvwProdCode.Rows.RemoveAt(e.RowIndex);MessageBox.Show("删除成功");}dgvwProdCode.Refresh();//刷新显示}else if (rectMod.Contains(curPosition))//修改{// FormProductOperate formProductOperate = new FormProductOperate();FormProductOperate formProductOperate = FormProductOperate.GetInstance();formProductOperate.Text = "修改产品";formProductOperate.btnAdd.Visible = false;formProductOperate.btnConfirm.Visible = true;formProductOperate.recipe = dgvwProdCode.Rows[dgvwProdCode.CurrentRow.Index].Cells[1].Value.ToString();formProductOperate.Show();dgvwProdCode.Refresh();//刷新显示}else if (rectIsEnable.Contains(curPosition)){IProduct product = new ProductImpl();//获取选中产品记录产品idstring recipe = dgvwProdCode.Rows[dgvwProdCode.CurrentRow.Index].Cells[1].Value.ToString();if (product.UpdateStatus(recipe) > 0){UpDataViewSource();MessageBox.Show("状态更改成功");}}}}}

在按钮上鼠标箭头变成小手样式

使用CellMouseMove方法

private void dgvwProdCode_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e){if (e.ColumnIndex >= 0 && e.RowIndex >= 0){Point curPosition = e.Location;//当前鼠标在当前单元格中的坐标if (this.dgvwProdCode.Columns[e.ColumnIndex].Name == "act"){this.Cursor = Cursors.Hand;//解决绘图时画面闪烁SetStyle(ControlStyles.UserPaint, true);SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲}}}

这样在DataGridView中完整的按钮和操作就完成。以及样式上的修改。

http://www.shuangfujiaoyu.com/news/29770.html

相关文章:

  • wordpress5.2下载seo的作用是什么
  • 做股权众筹的网站系统优化大师免费版
  • 尽请期待还是敬请期待免费seo排名优化
  • 邢台开发区网站公司网站怎么做
  • 手表网购最好的网站深圳全网推广公司
  • 在小说网站做编辑怎么找站长之家综合查询工具
  • 自备服务器做网站百度一下 官方网
  • php做网站怎么样百度seo推广是什么
  • 做网站标语制作网站平台
  • 推广普通话资料内容论述搜索引擎优化的具体措施
  • 邓州网站设计品牌营销策划公司哪家好
  • 佛山做pc端网站惠州网站建设方案推广
  • 做网站销售东西 需要什么资质百度推广代理加盟
  • ftp上传wordpress网站要多久app运营需要做哪些
  • 做网站一定要psd吗百度搜索风云榜小说总榜
  • 网站做整合页面seo网站排名优化教程
  • 建立网站坐等访问者发现怎样做网络推广营销
  • wordpress的主题说明博客seo优化技术
  • wordpress 医院模板下载淄博seo公司
  • 淄博专业网站设计中文域名交易平台
  • 做网站哪个语言好跨境电商平台有哪些?
  • 中小企业网站制作哪家好如何进行搜索引擎优化?
  • web开发就是做网站吗相亲网站排名前十名
  • 建设网站证书不受信任提交百度一下
  • 青岛中企动力做网站怎么样网络营销的四种形式
  • 优酷视频接到网站怎么做郑州网络公司
  • 专业做网站建设公司哪家好域名估价
  • 创建个人商城网站yahoo搜索引擎入口
  • 网站后台无法审核网站建设公司开发
  • 惠州市住房和城乡规划建设局官方网站百度北京总部电话