2024-05-13 11:10:35 +08:00
|
|
|
|
using NVelocity.Runtime.Parser.Node;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
2023-08-19 23:21:12 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
2024-05-13 11:10:35 +08:00
|
|
|
|
namespace WinformDevFramework
|
2023-08-19 23:21:12 +08:00
|
|
|
|
{
|
|
|
|
|
|
public static class ExtensionMethod
|
|
|
|
|
|
{
|
2024-05-13 11:10:35 +08:00
|
|
|
|
public static Image Base64ToImage(this string base64str)
|
2023-08-19 23:21:12 +08:00
|
|
|
|
{
|
2024-05-13 11:10:35 +08:00
|
|
|
|
if (string.IsNullOrEmpty(base64str))
|
2023-08-19 23:21:12 +08:00
|
|
|
|
{
|
2024-05-13 11:10:35 +08:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
byte[] imageBytes = Convert.FromBase64String(base64str);
|
|
|
|
|
|
using (MemoryStream memoryStream = new MemoryStream(imageBytes))
|
|
|
|
|
|
{
|
|
|
|
|
|
return Image.FromStream(memoryStream);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-08-19 23:21:12 +08:00
|
|
|
|
|
2024-05-13 11:10:35 +08:00
|
|
|
|
public static string ImageToBase64(this Image image)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (MemoryStream memoryStream = new MemoryStream())
|
|
|
|
|
|
{
|
|
|
|
|
|
image.Save(memoryStream, image.RawFormat);
|
|
|
|
|
|
byte[] imageBytes = memoryStream.ToArray();
|
|
|
|
|
|
return Convert.ToBase64String(imageBytes);
|
2023-08-19 23:21:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-05-13 11:10:35 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// combobox搜索功能
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="cb"></param>
|
|
|
|
|
|
/// <param name="strList"></param>
|
|
|
|
|
|
public static void TextUpdateFunction(this ComboBox cb, string[] strList)
|
2023-08-19 23:21:12 +08:00
|
|
|
|
{
|
2024-05-13 11:10:35 +08:00
|
|
|
|
try
|
2023-08-19 23:21:12 +08:00
|
|
|
|
{
|
|
|
|
|
|
{
|
2024-05-13 11:10:35 +08:00
|
|
|
|
string s = cb.Text; //获取cb_material控件输入内
|
|
|
|
|
|
List<string[]> strListNew = new List<string[]>();
|
|
|
|
|
|
//清空combobox
|
|
|
|
|
|
cb.DataSource = null;
|
|
|
|
|
|
cb.Items.Clear();
|
|
|
|
|
|
//遍历全部原始数据
|
|
|
|
|
|
foreach (var item in strList)
|
2023-08-19 23:21:12 +08:00
|
|
|
|
{
|
2024-05-13 11:10:35 +08:00
|
|
|
|
// 根据输入的值模糊查询,将符合条件的值存储到新strListNew的集合里面
|
|
|
|
|
|
if (item.Contains(s))
|
2023-08-19 23:21:12 +08:00
|
|
|
|
{
|
2024-05-13 11:10:35 +08:00
|
|
|
|
strListNew.Add(new string[] { "", item });
|
2023-08-19 23:21:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-05-13 11:10:35 +08:00
|
|
|
|
if (strListNew.Count >= 1) // 存在符合条件的内容
|
|
|
|
|
|
{
|
|
|
|
|
|
//将符合条件的内容加到combobox中
|
|
|
|
|
|
//this.ComCB.Items.AddRange(strListNew.ToArray());
|
|
|
|
|
|
GetComCB(cb, strListNew);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 不存在符合条件时
|
|
|
|
|
|
//设置光标位置,若不设置:光标位置始终保持在第一列,造成输入关键词的倒序排列
|
|
|
|
|
|
cb.SelectionStart = cb.Text.Length; // 设置光标位置,若不设置:光标位置始终保持在第一列,造成输入关键词的倒序排列
|
|
|
|
|
|
//cb.Cursor = Cursors.Default; //保持鼠标指针原来状态,有时候鼠标指针会被下拉框覆盖,所以要进行一次设置
|
|
|
|
|
|
cb.DroppedDown = true; // 自动弹出下拉框
|
|
|
|
|
|
cb.MaxDropDownItems = 8; // 自动弹出下拉框
|
2023-08-19 23:21:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-05-13 11:10:35 +08:00
|
|
|
|
catch (ArgumentOutOfRangeException e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(e);
|
|
|
|
|
|
}
|
2023-08-19 23:21:12 +08:00
|
|
|
|
}
|
2024-05-13 11:10:35 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设置combobox的item值
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="cb">ComboBox</param>
|
|
|
|
|
|
public static void GetComCB(ComboBox cb, List<string[]> res)
|
2023-08-19 23:21:12 +08:00
|
|
|
|
{
|
2024-05-13 11:10:35 +08:00
|
|
|
|
ArrayList mylist = new ArrayList();
|
|
|
|
|
|
foreach (var item in res)
|
2023-08-19 23:21:12 +08:00
|
|
|
|
{
|
2024-05-13 11:10:35 +08:00
|
|
|
|
mylist.Add(item[1]);
|
2023-08-19 23:21:12 +08:00
|
|
|
|
}
|
2024-05-13 11:10:35 +08:00
|
|
|
|
cb.Items.AddRange(mylist.ToArray());
|
2023-08-19 23:21:12 +08:00
|
|
|
|
}
|
2024-05-13 11:10:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-19 23:21:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|