disable scrolling when selecting text in richTextBox (C#) - text

I have a rich text box that contains (a lot of) text. I've added a search option for it, and when the user presses the search button, the program marks all the matches in yellow (by performing selectionBackColor on each selection) and then selects the first match.
The result is that the program looks like it "scans" the text and then selects the first match.
I don't want this to happen so I need to disable the autoscrolling (that occurs when performing Select()) for a specific code segment.
I searched this problem before posting and the main topics I found involved appending text, and that's not my case.
Any idea of how to solve my problem?
I'm using .NET framework 4 (visual studio 2010) and I write in C#.
Thanks in advance,
Guy

Well it seems that I'll answer my own question - all I had to do was to put these two lines among with the other class's properties:
[DllImport("user32.dll", EntryPoint = "LockWindowUpdate", SetLastError = true, CharSet = CharSet.Auto)]
private static extern IntPtr LockWindow(IntPtr Handle);
and surround the desired code segment with this at the start:
LockWindow(this.Handle);
and this at the end:
LockWindow(IntPtr.Zero);

Related

How to get the text of a menu item with its ID

I have an old visual prolog project in which I have to change the text of a menu during runtime.
This is what I've done to change the text:
menu_setText(Win, id_menu, NewMenuText)
This works fine, however, when I want to enable/disable this menu, the following does not work (meaning the menu item doesn't change its state):
menu_Enable(Win, id_menu, b_true)
After some search, I found that:
Under MS-Windows, submenus can not be referred to by a resource identifier. If the menu entry for a submenu, needs to enabled, disabled, checked or have the text changed. it is necessary to use a special versions of the menu_Enable, menu_Check and menu_SetText predicates, which specify the text of the menu entry instead of the constant.
menu_Enable(WinHandle, String, BOOLEAN)
menu_Check(WinHandle, String, BOOLEAN)
menu_SetText(WinHandle, String, NewString)
The weird thing is that in my case, menu_setText works just fine with the constant where menu_Enable requires the text itself. (yes I tested menu_Enable with the initial text of the menu item, but when the text changes then everything breaks)
Here comes my question:
How can I enable/disable a menu when I know its ID but not its name ?
If not possible directly, how can I get the current name of a menu when I know its ID ?
In case this helps, this project is opened and compiled with VIP52 (since before the year 2001).
I finally found a workaround that solves my problem, but I'm still not really satisfied, so if anyone comes up with a better answer, I'll take it !
I declared:
txt_menu(menu_tag,string)
And then called:
txt_menu(id_menu, MenuText),
menu_setText(Win, MenuText, NewText),
retractAll(txt_menu(id_menu,_)),
assert(txt_menu(id_menu,NewText)),
menu_Update(Win)
whenever I have to change the text of a menu item, and this can easily be transformed into a menu_setTextById predicate as such:
menu_setTextById(Win, MenuId, NewText):-
txt_menu(MenuId, MenuText),
menu_setText(Win, MenuText, NewText),
retractAll(txt_menu(MenuId,_)),
assert(txt_menu(MenuId, NewText)),
menu_Update(Win).
with the usage:
menu_setTextById(Win, id_menu, "My new text menu").
Noted that if I ever have the need to have several windows with menus, I'll have to add the Window Id to my txt_menu clause.
The main problem with this workaround is that I can't use & in the new text menu because if my menu has "&Menu" as text (meaning that M will be underlined), then trying to use menu_setText(Win,"&Menu","New Menu") will break because "&Menu" is not found.
So I'd need to remove any ampersand from the string before trying to use it in such predicates.

Do tabstops work in a MFC CCheckListBox?

I have a MFC CCheckListBox control working fine except Tab stops do not seem to work. When I supply the control with text strings that include the tab character ASCII 9 the text remains without any space for the Tabs.
Does anyone know if you can use tabstops in a CCheckListBox? I have tried a lot of different things and when I google I find same problem but no solutions. I have "Use Tabstops" box checked in the ListBox resource properties. I also have the Has Strings: True and Owner Draw: is Fixed (if that's any help). Here is the initialisation code that I am using:
BOOL CDlgQuotePOReceive::OnInitDialog()
{
CDialog::OnInitDialog();
VERIFY(((CCheckListBox *) this->GetDlgItem(IDC_LB_PO_DETAIL))->SetTabStops(10));
// Then code to fill the listbox with string data that
// is working fine to get the data into the control.
return TRUE;
}
The simple answer is no!
Reason: CCheckListBox ist just an owner draw list box. You can find the source code in the mfc. When the text is drawn the function just uses ExtTextOut and doesn't care about tab stops.
See implementation of CCheckListBox::DrawItem in VC\atlmfc\src\mfc\winctrl3.cpp
So the solution for you is also easy. Write your own class derived from CCheckedListBox and use your own DrawItem function. Also you have the source code of the current DrawItem function and you can easily use another text output function.

Visual Studio Control Recognition

The original problem:
I would add a control in a .aspx web form file, save it, and the designer code would not be appropriately updated. Therefore, my code behind file could not find any of the variables I was telling it about.
Things I tried to do that didn't work:
Converting the aspx file to web form. Storing the text inside, but deleting the files in the solution and re-adding them, re-adding code. Closing and opening VS.
Thing I tried that did work:
Deleting the files in the solution and re-adding them. Readded text bit by bit.
Emperical cause of the problem was in code behind aspx.cs file:
private const string RECORDSPERPAGE = "RecordsPerPage";
At any point in time after the addition of this variable (seen in this block)...
public partial class RequestSearch : ProtectedPage
{
private const string TOTALPAGES = "TotalPages";
private const string CURRENTPAGEINDEX = "CurrentPageIndex";
private const string RECORDSPERPAGE = "RecordsPerPage";
...if a control was added in the aspx file, the designer code was not updated appropriately and the code behind could not recognize the subsequently added controls, which were similar to this one...
I changed the name of this string constant to RESULTSPERPAGE. Everything worked after that.
So my problem is solved, it seems, but I have no idea why. RECORDSPERPAGE is not declared anywhere but that file, not used anywhere but in an analogous way to the other private string constants shown that do not cause the designer generation problem.
Hoping someone will have knowledge of the magic of Visual Studio that is allowing this kind of behavior, or alert me to somewhere else I might look to understand better the underlying cause of the problem.

hardcoded string “Button”, should use #string resource

I am new in Android app development and using Java language.
My problem is every time I make a TextView or Button there is a triangle with the exclamation mark below them.
and when I click it I saw a message saying:
hardcoded string “Button”, should use #string resource
I have two activities, in my main activity there is a Button that when you click it you will go in second activity.
But when I go to my main.java to make a code for the button. There's always the above shown error. I think the eclipse can't find the id of my button and same for my TextView they have same error message.
Here is the code I made:
Button b = FindViewById(R.id.button1);
I also add:
Button b = (Button) FindViewById(R.id.button1);
I am using the latest eclipse classic and ADT august issue. The platform is Android 4.1 API 16.
You shouldn't hardcode the "text" on the widgets use the strings resources ie., strings in the strings.xml to set the text. Declare the "text" you want to display as a string in strings.xml and access it using #string/your_string_name in the layout file.
Notice the id of the button, which is rounded in red. You have to use this id when you want to call it in a method, for an example
Button b = (Button) FindViewById(R.id.button1);
Furthermore, check whether your graphical layout matches with the image I have provided.
Just try your code again with these changes.
Your main.java would look like this.
I am a newbie too, but I believe I got this. So basically what's happening here, java wants you to put your hardcodes in string.xml. so that when accessing it, you will use the given methods below before:
.
But this is how it should be.
Let's start by string.xml
Then come back to your activity_main.xml

Can i change a static text in a Dialog after window came up in vc++ mfc application?

I am initialising a Dialog by using OnInitDialog and i initialized a static text as "loading"
now i had a function after it returns static text should change from "loading" to "initialized".
is this possible??
can text change even after a dialog came up??
Yes, of course it can. But you will have to change its ID to something other than IDC_STATIC. Then, you can use it like any other control.
Personally, I would create a control variable from it, and do
m_MyStatic.SetWindowText(L"Initialized");
(Not really. I would store the string in the STRINGTABLE and load it from there, buy you get the idea)

Resources