|
Member 11531487 wrote: when i click Find Next as want to be able to search for the next instance of the word. Hi, if you are not going to close the Form, and want to implement 'Select Next, then using 'ShowDialog is obviously not the right solution here.
One thing to think about: what if you do close the Form, but then, on the Main Form you define a special key-combination to "search next" ?
I will respond further within 18 hours.
cheers, Bill
«To kill an error's as good a service, sometimes better than, establishing new truth or fact.» Charles Darwin in "Prospero's Precepts"
|
|
|
|
|
I think there's a simple way to keep the search form open, and re-use it to find the next instance of a string. I would implement this by injecting a simple Action Delegate instance into the instance of the SearchForm at run-time (this is just a shortcut for creating a custom event; see the note at the end, here, for why I prefer this syntax):
public partial class SearchForm : Form
{
public SearchForm()
{
InitializeComponent();
}
public Action<string, bool> FindAction;
private string LastSearchText;
private string TextToFind;
private void btnCancel_Click(object sender, EventArgs e)
{
this.Hide();
}
private void btnFind_Click(object sender, EventArgs e)
{
TextToFind = textBox1.Text;
if (String.IsNullOrWhiteSpace(TextToFind))
{
MessageBox.Show("Searching on white space makes not sense.");
return;
}
FindAction(TextToFind, LastSearchText == TextToFind);
LastSearchText = TextToFind;
}
} When 'FindAction is invoked, it passes both the text the user wishes to search for, and a boolean flag that indicates whether the search is a new search, or a repeat of the previous search.
In the body of the Main Form:
SearchForm searchForm = new SearchForm();
private void Form1_Load(object sender, EventArgs e)
{
searchForm.Visible = false;
searchForm.Owner = this;
searchForm.FindAction = FindAction;
}
private void FindAction(string textToFind, bool isSameSearch)
{
int searchStartIndex = (isSameSearch)
? textBox1.SelectionStart + textBox1.SelectionLength
: 0;
int ndx = textBox1.Text.IndexOf(textToFind, searchStartIndex);
if (ndx == -1) return;
{
textBox1.SelectionStart = ndx;
textBox1.SelectionLength = textToFind.Length;
}
}
private void ShowSearchForm_Click(object sender, EventArgs e)
{
searchForm.Show();
} Notes:
1. You may wish to change the logic used here so that the search always begins at the current insertion point in the text ... where the cursor is ... rather than starting from the beginning ?
2. Why I prefer using an Action (or Func) delegate instance for "callbacks:"
a. while both Action and Func Types are "full-fledged" Delegate Types which can have multiple subscribers, with subscribers added and removed using the += and -= syntax:
b. when my intent is to use a delegate only as a callback in one specific "role" ... i.e., not to make the delegate available in a wider scope for use/subscription ... I think it more clearly expresses that intent to use Action/Func, and directly assign the callback function using = rather than +=.
Note that other folks may have other (strong) opinions about such a usage pattern with Action and Func.
«To kill an error's as good a service, sometimes better than, establishing new truth or fact.» Charles Darwin in "Prospero's Precepts"
|
|
|
|
|
Hi again your response is excellent as always the original code you sent me did indeed highlight the chosen word perfectly but now i have changed it to your most recent suggestion it is stopped at the line
FindAction(strToFind, LastSearchText == strToFind);
stating 'Object reference not set to an instance of an object.'
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SamsNotePad
{
public partial class frmFind : Form
{
public frmFind()
{
InitializeComponent();
}
public Action<string, bool> FindAction;
private string LastSearchText;
private string strToFind;
private void Cancel_Click(object sender, EventArgs e)
{
this.Hide();
}
private void cmdFind_Click(object sender, EventArgs e)
{
strToFind = searchTxt.Text;
if (string.IsNullOrWhiteSpace(strToFind))
{
MessageBox.Show("Please enter search text");
return;
}
FindAction(strToFind, LastSearchText == strToFind);
LastSearchText = strToFind;
}
}
}
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;
using System.IO;
using System.Drawing.Printing;
namespace SamsNotePad
{
public partial class Form1 : Form
{
frmFind FindForm = new frmFind();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
FindForm.Visible = false;
FindForm.Owner = this;
FindForm.FindAction = findAction;
}
private void findAction(string strToFind, bool isSameSearch)
{
int searchStartIndex = (isSameSearch)
? textBox1.SelectionStart + textBox1.SelectionLength : 0;
int ndx = textBox1.Text.IndexOf(strToFind, searchStartIndex);
if (ndx == -1) return;
textBox1.SelectionStart = ndx;
textBox1.SelectionLength = strToFind.Length;
}
private void findToolStripMenuItem_Click(object sender, EventArgs e)
{
FindForm.Show();
}
private void findNextToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void goToToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
{
textBox1.SelectAll();
}
private void timeDateToolStripMenuItem_Click(object sender, EventArgs e)
{
textBox1.Text += DateTime.Now;
}
private void statusToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void wordWrapToolStripMenuItem_Click(object sender, EventArgs e)
{
wordWrapToolStripMenuItem.Checked = !(wordWrapToolStripMenuItem.Checked); textBox1.WordWrap = wordWrapToolStripMenuItem.Checked;
}
private void fontToolStripMenuItem_Click(object sender, EventArgs e)
{
if (fontDialog1.ShowDialog() == DialogResult.OK)
textBox1.Font = fontDialog1.Font;
}
public Action<string, bool> FindAction { get; set; }
}
}
|
|
|
|
|
Put a break-point on the line where the code stops and examine the state of the variables (object references) on that line.
Figure out which one(s) are null, and work backwards from that to figuring out why that is.
cheers, Bill
«To kill an error's as good a service, sometimes better than, establishing new truth or fact.» Charles Darwin in "Prospero's Precepts"
|
|
|
|
|
Server want to distribute some files into the clients without request of client.How can I do it..plz i need help..
|
|
|
|
|
Using what protocol? Email? How is this related to C#?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Write a Windows service that you install on the clients which listens for requests and can receive and save files. Or utilize the default "hidden" share that windows sets up. The client's "C" drive will be
\\clientname\c$
so you can save files to
\\clientname\c$\somefolder\somefile.txt
To do this the process needs the required permissions, and there is no guarantee the share exists as the user might have removed the default share.
|
|
|
|
|
I have a problem getting a string from a element from a rss feed.
i get error here:
XmlNode sizeNode = xmlnode.SelectSingleNode("torrent:contentLength");
the code runs if i leave out that line. here is rest of it:
private void button1_Click(object sender, EventArgs e)
{
var xmlDoc = new XmlDocument();
xmlDoc.Load("movies.xml");
var xmlNode = xmlDoc.SelectSingleNode("//rss/channel");
var i = 0;
foreach (XmlNode xmlnode in xmlNode)
{
XmlNode titleNode = xmlnode.SelectSingleNode("title");
XmlNode categoryNode = xmlnode.SelectSingleNode("category");
XmlNode dateNode = xmlnode.SelectSingleNode("pubDate");
XmlNode sizeNode = xmlnode.SelectSingleNode("torrent:contentLength");
if ((titleNode != null) && (dateNode != null) &&
(categoryNode != null) && (sizeNode != null) )
{
DgvMain.Rows.Add();
DgvMain.Rows[i].Cells[1].Value = titleNode.InnerText;
DgvMain.Rows[i].Cells[2].Value = categoryNode.InnerText;
DgvMain.Rows[i].Cells[3].Value = dateNode.InnerText;
DgvMain.Rows[i].Cells[4].Value = sizeNode.InnerText;
i++;
}
}
here is a part from xml file:
="1.0"="UTF-8"
<rss version="2.0" xmlns:torrent="http://xmlns.ezrss.it/0.1/">
<channel>
<title>movies torrents RSS feed - KickassTorrents</title>
<link>http://kickass.to/</link>
<description>movies torrents RSS feed</description>
<item>
<title>Al Murray My Gaff My Rules 2003 Xvid Mp3.avi</title>
<category>Movies</category>
<author>http://kickass.to/user/Stull/</author> <link>http://kickass.to/al-murray-my-gaff-my-rules-2003-xvid-mp3-avi-t10314315.html</link>
<guid>http://kickass.to/al-murray-my-gaff-my-rules-2003-xvid-mp3-avi-t10314315.html</guid>
<pubDate>Sat, 07 Mar 2015 00:27:56 +0000</pubDate>
<torrent:contentLength>548352170</torrent:contentLength>
<torrent:infoHash>EDBA9CB0942265440B3A0AC6FD70B39CD4384E54</torrent:infoHash>
<torrent:magnetURI><![CDATA[</torrent:magnetURI>
<torrent:seeds>1</torrent:seeds>
<torrent:peers>1</torrent:peers>
<torrent:verified>0</torrent:verified>
<torrent:fileName>al.murray.my.gaff.my.rules.2003.xvid.mp3.avi.torrent</torrent:fileName>
<enclosure url="http://torcache.net/torrent/EDBA9CB0942265440B3A0AC6FD70B39CD4384E54.torrent?title=[kickass.to]al.murray.my.gaff.my.rules.2003.xvid.mp3.avi" length="548352170" type="application/x-bittorrent" />
</item>
I would appriciate any help..
|
|
|
|
|
The problem is that you are missing a reference to the XML Namespace torrent from your code. The XML cannot parse this node without this information. Something like this should help
var ns = new XmlNamespaceManager(doc.NameTable);
ns.AddNamespace("torrent", "http://xmlns.ezrss.it/0.1/");
|
|
|
|
|
Hi all,
I need some help since I searched thru all of the blogs and could not find the answer. I have the following code in C# and will like to call ONPaint() in the DrawEventHandler(object sender, DrawHandler.DrawEventArgs e)
I get this error:
Error 1 The best overloaded method match for 'System.Windows.Forms.Control.OnPaint(System.Windows.Forms.PaintEventArgs)' has some invalid arguments
Error 2 Argument '1': cannot convert from 'mobile.DrawSHandler.DrawEventArgs' to 'System.Windows.Forms.PaintEventArgs'
namespace mobile
{
public partial class SV : UserControl
{
code for declaring variables
public SV()
{
code........
}
private void DrawEventHandler(object sender, DrawHandler.DrawEventArgs e)
{
OnPaint();
}
protected override void OnPaint(PaintEventArgs e)
{
Bitmap b = new Bitmap(this.Width, this.Height);
Graphics g = Graphics.FromImage(b);
Brush bg = new SolidBrush(BackColor);
Region bgr = new Region(new Rectangle(0, 0, this.Width, this.Height));
g.FillRegion(bg, bgr);
DrawBg(g);
DrawSV(g);
e.Graphics.DrawImage(b, 0, 0);
b.Dispose();
g.Dispose();
}
protected void DrawBg(Graphics g)
{
code........
}
protected void DrawSV(Graphics g)
{
code........
}
}
}
|
|
|
|
|
You can't just omit parameters; the compiler will look for a method without parameters and says, correctly, that there is none.
Call <a href="https://msdn.microsoft.com/en-us/library/598t492a(v=vs.110).aspx">Invalidate</a>[<a href="https://msdn.microsoft.com/en-us/library/598t492a(v=vs.110).aspx" target="_blank" title="New Window">^</a>] to have the control repaint.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
thanks, this works
private void DrawEventHandler(object sender, DrawHandler.DrawEventArgs e)
{
this.Invalidate();
}
|
|
|
|
|
hi all,
i have a form that have a container.
in the container - datagridview and button
container is hortizal
name of this form: MAIN
button event click:
duplicate MAIN form
but i want that the container will be vertical in the duplicate form
how i can do this??
thanks you
|
|
|
|
|
Add a default parameter to the main form constructor:
public frmMain(bool IsHorizontal = true)
{
InitializeComponent();
...
}
Then check the value in the constructor and orient your container appropriately.
When you want a vertical container:
frmMain fm = new frmMain(false);
fm.Show();
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
how i do when IsHorizontal=true
then the frm will show but VERTICAL
|
|
|
|
|
|
Hi All,
How to create PPPoE connection after clicking button in c#. I have ready form with two textbox(username and password)fields. I want to create PPPoE Connection, place shortcut on desktop and copy username and password from fields to PPPoE connection after clicking button in form.
Thanks for Helping.
-*-*-*-*-*-*-*-*-*
To Be Or Not To Be
(KARFER)
-*-*-*-*-*-*-*-*-*
modified 16-Mar-15 10:46am.
|
|
|
|
|
And?
What have you tried?
Where are you stuck?
What help do you need?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
Don't post this here - if you got the code from an article, then there is a "Add a Comment or Question" button at the bottom of that article, which causes an email to be sent to the author. They are then alerted that you wish to speak to them.
Posting this here relies on them "dropping by" and realising it is for them.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I want to write multiple attributes and their values in single node without closing tag in c#.
|
|
|
|
|
And at which point did you run into a problem?
Recursion: see Recursion.
|
|
|
|
|
If you had a question, we could help. As is, I can only wish you good luck with your intention
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
XElement request = new XElement( "IntlRateV2Request",
new XAttribute( "USERID", _username ),
new XAttribute( "PASSWORD", _password )
);
request.Add( new XElement( "Revision", "2" ) );
etc.
|
|
|
|