/// <summary> /// 将resx文件转换为resources文件,如果转换成功,返回True /// </summary> /// <param name="strResources">resources文件的路径,注意请保证路径正确无误</param> /// <param name="strResx">resx文件的路径,注意请保证路径正确无误</param> public static bool ConvertResources(string strResx, string strResources) { if (string.IsNullOrEmpty(strResources) || string.IsNullOrEmpty(strResx)) { return(false); } if (File.Exists(strResources) && File.Exists(strResx) == false) { return(false); } //开始转换. try { //ResourceReader reader = new ResourceReader(strResources); ResXResourceSet reader = new ResXResourceSet(strResx); //ResXResourceWriter writer = new ResXResourceWriter(strResx); ResourceWriter writer = new ResourceWriter(strResources); foreach (DictionaryEntry en in reader) { writer.AddResource(en.Key.ToString(), en.Value); } reader.Close(); writer.Close(); } catch { return(false); } return(true); }
protected override void OnClosed(EventArgs e) { if (resourceSet != null) { //release resources resourceSet.Close(); } base.OnClosed(e); }
private void OpenFile(string fileName) { FileStream file; try { xmlDocument = new XmlDataDocument(); xmlDocument.DataSet.ReadXmlSchema(fileName); file = new FileStream(fileName, FileMode.Open, FileAccess.Read); xmlDocument.Load(file); file.Close(); xmlGridView.DataSource = xmlDocument.DataSet; xmlGridView.DataMember = "data"; //we need this to exclude non-text fields file = new FileStream(fileName, FileMode.Open, FileAccess.Read); resourceSet = new ResXResourceSet(file); } catch (Exception ex) { isDocumentOpen = false; ReportError(ex.Message); return; } xmlFileName = fileName; InitGrid(); //hide non-text fields foreach (DictionaryEntry d in resourceSet) { if (d.Value == null || d.Value.GetType() != typeof(string)) { foreach (DataGridViewRow row in xmlGridView.Rows) { if (row.Cells["name"].Value.ToString() == d.Key.ToString()) { row.Visible = false; } } } } //release resources resourceSet.Close(); file.Close(); isDataModified = false; isDocumentOpen = true; UpdateForm(); }
/// <summary> /// Allow to create Image objects from the ressource file create in loadPictureInResource /// </summary> public void loadImageFromRessource() { ResXResourceSet resxSet = new ResXResourceSet("Resources.resx"); correspondIndiceName = new Dictionary <string, int>(); foreach (DictionaryEntry d in resxSet) { ImageFeedbacksPerso img = new ImageFeedbacksPerso(); img.chooseCorrectName((string)d.Key); img.bitmapOpenGL = (Bitmap)d.Value; img.image = Bitmap2BitmapImage(img.bitmapOpenGL); listImg.Add(img); } resxSet.Close(); }
public ResourceManager(string ResxFile) : this() { System.IO.FileInfo f = new System.IO.FileInfo(ResxFile); if (f.Exists) { var st = new ResXResourceSet(ResxFile); foreach (DictionaryEntry e in st) { IResourceHolder hld = loader.CreateHolderInstance(e.Key.ToString(), e.Value); if (hld != null) { List.Add(hld); } else { incomplete = true; } } st.Close(); } fileName = ResxFile; }
private async void button10_Click(object sender, EventArgs e) { try { ResXResourceSet resX = new ResXResourceSet(Resources.ResourceManager.BaseName); byte[] _byteArr = (byte[])resX.GetObject("resource1"); if (!(_byteArr.Equals(null))) { Bitmap bitmap = await ByteToImageAsync(_byteArr); pictureBox1.Image = bitmap; textBox1.AppendText($"res added to picBox{Environment.NewLine}"); } resX.Close(); resX.Dispose(); resX = null; } catch (Exception exc) { textBox1.AppendText($"res not added to pic => {exc.ToString()}{Environment.NewLine}"); } }