public void LoadDroppedFile(IDataObject data) { if (!data.GetDataPresent(DataFormats.FileDrop)) { return; } var filePaths = (string[])(data.GetData(DataFormats.FileDrop)); if (filePaths == null || filePaths.Length <= 0) { return; } var filePath = filePaths[0]; if (filePath == null) { return; } var ext = Path.GetExtension(filePath); ext = ext.ToLower(); if (String.Compare(ext, ".sdf", StringComparison.OrdinalIgnoreCase) != 0) { return; } dataSource = filePaths[0]; AnalyzeDatabase(); }
private void InsertAnswerImage() { //获取剪切板上的图片,如果剪切板上的图片为空,则提示 System.Windows.IDataObject clip1 = System.Windows.Clipboard.GetDataObject(); bool ifCanGetClilp = clip1.GetDataPresent(typeof(System.Drawing.Bitmap)); if (true == ifCanGetClilp) { Bitmap clipBitMap = (Bitmap)clip1.GetData(typeof(System.Drawing.Bitmap)); String imagePath = @"../../TestCases/temp.png"; clipBitMap.Save(imagePath, System.Drawing.Imaging.ImageFormat.Png); int QuestionID = 0; int.TryParse(textBox4.Text, out QuestionID); try { Question u = Question.Find(QuestionID); u.AnswerMedia_width = clipBitMap.Width; u.AnswerMedia_height = clipBitMap.Height; clipBitMap.Dispose(); FileStream fs1 = new FileStream(imagePath, FileMode.Open, FileAccess.Read); Byte[] tempFile3 = new Byte[fs1.Length]; fs1.Read(tempFile3, 0, (int)fs1.Length); u.AnswerMediaContent = tempFile3; u.UpdateAndFlush(); fs1.Close(); textBlock1.Text = "答案图片:" + u.AnswerMedia_width.ToString(); } catch { MessageBox.Show("找不到题序"); } } }
public static IEnumerable <IFile> GetFileDescriptorFiles(this System.Windows.IDataObject data) { if (data == null || !data.GetDataPresent(WideFileGroupDescriptorFormat)) { return(new IFile[0]); } return(NamesWithPositions(data).Select(i => new LazyStreamFile(i.Item2, () => GetFileByIndex(data, i.Item1)))); }
/// <summary> /// コピーした項目を貼り付け /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PasteItem_Execute(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) { // クリップボードの文字列をItemにパースして追加 System.Windows.IDataObject data = System.Windows.Clipboard.GetDataObject(); if (data.GetDataPresent(System.Windows.DataFormats.CommaSeparatedValue)) { string str = (string)data.GetData(System.Windows.DataFormats.CommaSeparatedValue); mViewModel.Items.Add(ViewModel.Item.Parse(str)); } }
public static string GetTextPath() { System.Windows.IDataObject data = Clipboard.GetDataObject(); string ClipboardText = ""; if (data.GetDataPresent(DataFormats.Text)) { ClipboardText = (string)data.GetData(DataFormats.Text); // クリップボードのテキストを改行毎に配列に設定 string[] ClipBoardList = ClipboardText.Split('\n'); foreach (string file in ClipBoardList) { FileInfo fileinfo = new FileInfo(file); DirectoryInfo dirinfo = new DirectoryInfo(file); if (fileinfo.Exists || dirinfo.Exists) { ClipboardText = fileinfo.FullName; break; } } } if (data.GetDataPresent(DataFormats.FileDrop)) { foreach (string file in (string[])data.GetData(DataFormats.FileDrop)) { FileInfo fileinfo = new FileInfo(file); DirectoryInfo dirinfo = new DirectoryInfo(file); if (fileinfo.Exists || dirinfo.Exists) { ClipboardText = fileinfo.FullName; break; } } } return(ClipboardText); }
private string GetStringData() { string ret = ""; System.Windows.IDataObject iData = System.Windows.Clipboard.GetDataObject(); if (iData.GetDataPresent(System.Windows.DataFormats.Text)) { ret = (string)iData.GetData(System.Windows.DataFormats.Text); } return(ret); }
private void BasicTest() { Question u = Question.Find(3); //label1.Content = u.用户名; u = Question.Find(3); //通过剪切板进入到数据库 System.Windows.IDataObject clip1 = System.Windows.Clipboard.GetDataObject(); bool ifCanGetClilp = clip1.GetDataPresent(typeof(System.Drawing.Bitmap)); //object clipBitMap = clip1.GetData(DataFormats.Bitmap); Bitmap clipBitMap = (Bitmap)clip1.GetData(typeof(System.Drawing.Bitmap)); String imagePath = @"../../TestCases/temp.png"; //另存为临时文件 clipBitMap.Save(imagePath, System.Drawing.Imaging.ImageFormat.Png); u.Media_width = clipBitMap.Width; u.Media_height = clipBitMap.Height; clipBitMap.Dispose(); //读一个二进制文件,将该文件内容写入到DB中 FileStream fs1 = new FileStream(imagePath, FileMode.Open, FileAccess.Read); Byte[] tempFile3 = new Byte[fs1.Length]; fs1.Read(tempFile3, 0, (int)fs1.Length); u.MediaContent = tempFile3; u.AnswerText = "测试"; u.UpdateAndFlush(); fs1.Close(); u = Question.TryFind(4); if (u == null) { u = new Question(); u.QuestionID = 4; //u.用户名 = "u4"; u.CreateAndFlush(); } else { u.DeleteAndFlush(); } }
public static string GetText() { System.Windows.IDataObject data = Clipboard.GetDataObject(); string ClipboardText = ""; if (data.GetDataPresent(DataFormats.Text)) { ClipboardText = (string)data.GetData(DataFormats.Text); // クリップボードのテキストを改行毎に配列に設定 string[] ClipBoardList = ClipboardText.Split('\n'); ClipboardText = string.Join(" ", ClipBoardList); /* * foreach (string text in ClipBoardList) * { * if (text.Trim().Length > 0) * ClipboardText = text; * } */ } if (data.GetDataPresent(DataFormats.FileDrop)) { foreach (string file in (string[])data.GetData(DataFormats.FileDrop)) { FileInfo fileinfo = new FileInfo(file); DirectoryInfo dirinfo = new DirectoryInfo(file); if (fileinfo.Exists || dirinfo.Exists) { ClipboardText = fileinfo.Name; break; } } } return(ClipboardText); }
private void getClipDataFromPC() { byte[] PCClipData = null; //PC向Phone侧发起握手,开始写 String handShakeFlag = "00000000"; byte[] data = System.Text.Encoding.Default.GetBytes(handShakeFlag); /* int ret = DR2.Server.DataManager.sendRawData(data); * if (ret == -1) * { * System.Windows.Forms.MessageBox.Show("pc与phone通信失败"); * } * * else */ { //获得pc剪贴板内容,往手机侧送 // GetDataObject检索当前剪贴板上的数据 System.Windows.IDataObject iData = System.Windows.Clipboard.GetDataObject(); // 将数据与指定的格式进行匹配,返回bool if (iData.GetDataPresent(System.Windows.DataFormats.Text)) { // GetData检索数据并指定一个格式 String clipText = (string)iData.GetData(System.Windows.DataFormats.Text); PCClipData = System.Text.Encoding.Default.GetBytes(clipText); } else { System.Windows.Forms.MessageBox.Show("剪贴板中数据不可转换为文本", "错误"); } int isSuccess = DataManager.sendRawData(PCClipData); //if(isSuccess==1) // System.Windows.Forms.MessageBox.Show("pc向手机拷贝成功"); //else // System.Windows.Forms.MessageBox.Show("pc向手机拷贝失败"); } }
private static bool AcceptDrop(IDataObject data) { return(data != null && data.GetDataPresent(DataFormats.FileDrop)); }