I want to close my console using a close method. Not via the X - console

I have a small problem. I want to close my console using a close method. Not via the X.
For this I have a case "9" in the switch block;
This means that when I enter "9" and press enter, the window should close. The previous attempts to call Application.Close(); with a method did not work.
Does anyone have a solution, or is this not even possible from the switch?
private void InputOption()
{
string input;
Menu nextMenu;
while(true) //Die Eingabe muss die zahlen beinhalten.
{
Console.Write("Eingabe: ");
input = Console.ReadLine();
bool correctInput = true;
switch(input)
{
case "1":
nextMenu = new CreateProfileMenu();
break;
case "2":
nextMenu = new LoadProfileMenu();
break;
case "9":
Close();
break;
default:
correctInput = false;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Ungültige Eingabe!");
Console.ForegroundColor = ConsoleColor.DarkCyan;
break;
}
if (correctInput)
{
break;
}
}

I have found the problem. The assembly
I have found the error. There was a missing link to System.Windows.Forms;
I have now successfully implemented the method Close() in the Switch Block.
case "9" :
Close();
...
private void Close()
{
Application.Exit();
}

Related

SelectionMode.MULTIPLE with TAB to navigate to next cell

I'm currently using TAB to navigate to next cell. selectNext() or selectRightCell() works fine when I'm using SelectionMode.SINGLE.
However, when using SelectionMode.MULTIPLE, its selecting multiple cells as I TAB.
I'm using a TableView. I need SelectionMode.MULTIPLE for the copy & paste function.
Is there a way to make it work in SelectionMode.MULTIPLE?
fixedTable.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
#Override
public void handle(KeyEvent event) {
switch (event.getCode()){
case TAB:
if (event.isShiftDown()) {
fixedTable.getSelectionModel().selectPrevious();
} else {
fixedTable.getSelectionModel().selectNext();
}
event.consume();
break;
case ENTER:
return;
case C:
if(event.isControlDown()){
copySelectionToClipboard(fixedTable) ;
}
event.consume();
break;
case V:
if(event.isControlDown()){
pasteFromClipboard(fixedTable);
}
event.consume();
break;
default:
if (fixedTable.getEditingCell() == null) {
if (event.getCode().isLetterKey() || event.getCode().isDigitKey()) {
TablePosition focusedCellPosition = fixedTable.getFocusModel().getFocusedCell();
fixedTable.edit(focusedCellPosition.getRow(), focusedCellPosition.getTableColumn());
}
}
break;
}
}
});
You will need to handle the selection on your own. The reason is because the methods selectPrevious() and selectNext() tries to select the previous ( or the next ) without removing the current selected row ( when you set the selection mode to be SelectionMode.MULTIPLE) , also you can't use them and just remove the previous selecting by just calling clearSelection() because this will set the selected index to -1 and then the methods selectPrevious() and selectNext() will select the last or the first row only.
Here is how you could implement the selection on your own :
// the rest of your switch statement
...
case TAB:
// Find the current selected row
int currentSelection = table.getSelectionModel().getSelectedIndex();
// remove the previous selection
table.getSelectionModel().clearSelection();
if (event.isShiftDown()) {
currentSelection--;
} else {
currentSelection++;
}
// find the size of our table
int size = table.getItems().size() - 1;
// we was on the first element and we try to go back
if(currentSelection < 0){
// either do nothing or select the last entry
table.getSelectionModel().select(size);
}else if(currentSelection > size) {
// we are at the last index, do nothing or go to 0
table.getSelectionModel().select(0);
}else {
// we are between (0,size)
table.getSelectionModel().select(currentSelection);
}
event.consume();
break;
...

error: expected primary-expression before '}' token

void ChangeStates(void)
{
int i;
for (i=0; i<CELLS; i++)
{
switch (state[i])
{
case IMMUNE:
timer[i]--;
if(timer[i]==0)
state[i] = HEALTHY;
break;
case INFECTED:
timer[i]--;
if(timer[i]==0)
{
state[i] = IMMUNE;
timer[i] = IMM_TIME;
}
break;
case EXPOSED:
timer[i]--;
if(timer[i]==0)
{
state[i] = INFECTED;
timer[i] = INF_TIME;
}
break;
default:
} //Here is the error
}
}
The program intend to do something about disease dynamics in plants, and use the switch function to change the state of cells.
I am using Qt Creator 5.5 as a beginner.
But I do not know how to fix this error.
Thanks in advance
'default' has to be followed by a statement, 'break;' will work. Or remove the default as was suggested, this might mean better warnings also (unhandled enumeration value in switch, which is always good to catch).
You could also do 'qFatal' in the default to again catch an unhandled state[] value in the switch.

Virtual Buttons (Vuforia) don't wait for touch

Having really strange problem. Lots of people can't make VB work at all, but my buttons activate as soon as the target is found, automaticaly!
I have 4 buttons and 4 URL link on them. When target is found my browser open ALL these links in one moment.
Script is a component of ImageTarget.
My code:
void Start() {
VirtualButtonBehaviour[] vbs = GetComponentsInChildren<VirtualButtonBehaviour>();
for (int i = 0; i < vbs.Length; ++i) {
// Register with the virtual buttons TrackableBehaviour
vbs[i].RegisterEventHandler(this);
}}
public void OnButtonPressed(VirtualButtonAbstractBehaviour vb) {
switch (vb.VirtualButtonName) {
case "VBtn1":
Application.OpenURL("http://www.shop.mts.ru/smartfony/nokia/smartfon-lumia-830-black.html");
break;
case "VBtn2":
Application.OpenURL("http://www.youtube.com/watch?v=kMwQ9Fxp5_g");
break;
case "VBtn3":
Application.OpenURL("https://vk.com/mts");
break;
case "VBtn4":
Application.OpenURL("https://www.facebook.com/mts?fref=ts");
break;
}
}
public void OnButtonReleased(VirtualButtonAbstractBehaviour vb) {
return;
}
Plz, tell me, what I'm doing wrong :(

Setting default TWAIN data source without using API UI menu

Using the twaindotnet library in C#, I'm wondering if there's a way to set the default datasource using the library.
As a feeble attempt, I've tried adding a SetDefault method to the DataSource class of twaindonet, like this
public static void SetDefault(Identity applicationId, IWindowsMessageHook messageHook, DataSource newDataSource)
{
var defaultSourceId = newDataSource.SourceId;
// Attempt to get information about the system default source
var result = Twain32Native.DsmIdentity(
applicationId,
IntPtr.Zero,
DataGroup.Control,
DataArgumentType.Identity,
Message.Set,
defaultSourceId);
if (result != TwainResult.Success)
{
var status = DataSourceManager.GetConditionCode(applicationId, null);
throw new TwainException("Error getting information about the default source: " + result, result, status);
}
}
which is called from the DataSourceManage class like this
public void SelectSource(DataSource dataSource)
{
DataSource.Dispose();
DataSource.SetDefault(ApplicationId, _messageHook, dataSource);
}
But when I try to use SetDefault, Twain32Native.DsmIdentity always results in Failure being returned.
I basically copied from SetDefault the setDefaultDataSource method from TWAIN sample Data Source and Application
pTW_IDENTITY TwainApp::setDefaultDataSource(unsigned int _index)
{
if(m_DSMState < 3)
{
cout << "You need to open the DSM first." << endl;
return NULL;
}
else if(m_DSMState > 3)
{
PrintCMDMessage("A source has already been opened, please close it first\n");
return NULL;
}
if(_index >= 0 && _index < m_DataSources.size())
{
m_pDataSource = &(m_DataSources[_index]);
// set the specific data source
TW_UINT16 twrc;
twrc = _DSM_Entry(
&m_MyInfo,
0,
DG_CONTROL,
DAT_IDENTITY,
MSG_SET,
(TW_MEMREF) m_pDataSource);
switch (twrc)
{
case TWRC_SUCCESS:
break;
case TWRC_FAILURE:
printError(0, "Failed to get the data source info!");
break;
}
}
else
{
return NULL;
}
return m_pDataSource;
}
Any help would be greatly appreciated.
The possible cause is that the version of your TWAIN DSM is too low. Only DSM 2.0 or above supports setting default TWAIN data source.

How to use enum in if statement?

I have ASP.NET application and want to use enum in if statement.
I get variable in this way:
string choice = (string)Session["export_choice"];
if(choice == <here goes enum>)
{
}
else
{
}
enum can have 2 string values only.
this is normally where I would use a switch:
myEnumType myEnumChoice;
if (Enum.TryParse(choice, out myEnumChoice))
{
switch(myEnumChoice)
{
case myEnumType.FirstEnum:
//doSomething();
break;
case myEnumType.SecondEnum:
//doSomethingElse();
break;
}
}
else
throw new ArgumentException(string.Format("Unexpected enum value: {0}", choice));
use
EnumChoice choice = (EnumChoice) Enum.Parse(typeof(ChumChoice), (string)Session["export_choice"] , true);
EnumChoice is enum type
you can use it like
if(choice== EnumChoice.X)
{
}
else
{
}

Resources